Commit 0c1e9930 authored by Nick Thomas's avatar Nick Thomas

Use accelerated uploads for users/personal snippets

parent 33a5eb7d
......@@ -44,10 +44,12 @@ type routeOptions struct {
}
const (
apiPattern = `^/api/`
ciAPIPattern = `^/ci/api/`
gitProjectPattern = `^/([^/]+/){1,}[^/]+\.git/`
projectPattern = `^/([^/]+/){1,}[^/]+/`
apiPattern = `^/api/`
ciAPIPattern = `^/ci/api/`
gitProjectPattern = `^/([^/]+/){1,}[^/]+\.git/`
projectPattern = `^/([^/]+/){1,}[^/]+/`
snippetUploadPattern = `^/uploads/personal_snippet`
userUploadPattern = `^/uploads/user`
)
func compileRegexp(regexpStr string) *regexp.Regexp {
......@@ -217,6 +219,8 @@ func (u *upstream) configureRoutes() {
// Uploads
route("POST", projectPattern+`uploads\z`, upload.Accelerate(api, proxy)),
route("POST", snippetUploadPattern, upload.Accelerate(api, proxy)),
route("POST", userUploadPattern, upload.Accelerate(api, proxy)),
// For legacy reasons, user uploads are stored under the document root.
// To prevent anybody who knows/guesses the URL of a user-uploaded file
......
......@@ -102,10 +102,6 @@ func parseJWT(token *jwt.Token) (interface{}, error) {
}
func TestAcceleratedUpload(t *testing.T) {
reqBody, contentType, err := multipartBodyWithFile()
if err != nil {
t.Fatal(err)
}
ts := uploadTestServer(t, func(r *http.Request) {
jwtToken, err := jwt.Parse(r.Header.Get(upload.RewrittenFieldsHeader), parseJWT)
require.NoError(t, err)
......@@ -120,14 +116,16 @@ func TestAcceleratedUpload(t *testing.T) {
ws := startWorkhorseServer(ts.URL)
defer ws.Close()
resource := `/example`
resp, err := http.Post(ws.URL+resource, contentType, reqBody)
if err != nil {
t.Error(err)
}
defer resp.Body.Close()
if resp.StatusCode != 200 {
t.Errorf("GET %q: expected 200, got %d", resource, resp.StatusCode)
resources := []string{`/example`, `/uploads/personal_snippet`, `/uploads/user`}
for _, resource := range resources {
reqBody, contentType, err := multipartBodyWithFile()
require.NoError(t, err)
resp, err := http.Post(ws.URL+resource, contentType, reqBody)
require.NoError(t, err)
require.Equal(t, 200, resp.StatusCode)
resp.Body.Close()
}
}
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment