Commit e783a3d0 authored by Jacob Vosmaer's avatar Jacob Vosmaer

Clean up handling of the Temp-Path header

parent b4037dcf
...@@ -7,7 +7,7 @@ import ( ...@@ -7,7 +7,7 @@ import (
func (u *upstream) artifactsAuthorizeHandler(h handleFunc) handleFunc { func (u *upstream) artifactsAuthorizeHandler(h handleFunc) handleFunc {
return u.preAuthorizeHandler(func(w http.ResponseWriter, r *gitRequest) { return u.preAuthorizeHandler(func(w http.ResponseWriter, r *gitRequest) {
req := r.Request req := r.Request
req.Header.Set("Gitlab-Workhorse-Temp-Path", r.TempPath) req.Header.Set(tempPathHeader, r.TempPath)
h(w, req) h(w, req)
}, "/authorize") }, "/authorize")
} }
...@@ -11,6 +11,8 @@ import ( ...@@ -11,6 +11,8 @@ import (
"os" "os"
) )
const tempPathHeader = "Gitlab-Workhorse-Temp-Path"
func rewriteFormFilesFromMultipart(r *http.Request, writer *multipart.Writer, tempPath string) (cleanup func(), err error) { func rewriteFormFilesFromMultipart(r *http.Request, writer *multipart.Writer, tempPath string) (cleanup func(), err error) {
// Create multipart reader // Create multipart reader
reader, err := r.MultipartReader() reader, err := r.MultipartReader()
...@@ -84,11 +86,12 @@ func rewriteFormFilesFromMultipart(r *http.Request, writer *multipart.Writer, te ...@@ -84,11 +86,12 @@ func rewriteFormFilesFromMultipart(r *http.Request, writer *multipart.Writer, te
} }
func (u *upstream) handleFileUploads(w http.ResponseWriter, r *http.Request) { func (u *upstream) handleFileUploads(w http.ResponseWriter, r *http.Request) {
tempPath := r.Header.Get("Gitlab-Workhorse-Temp-Path") tempPath := r.Header.Get(tempPathHeader)
if tempPath == "" { if tempPath == "" {
fail500(w, errors.New("handleFileUploads: TempPath empty")) fail500(w, errors.New("handleFileUploads: TempPath empty"))
return return
} }
r.Header.Del(tempPathHeader)
var body bytes.Buffer var body bytes.Buffer
writer := multipart.NewWriter(&body) writer := multipart.NewWriter(&body)
......
...@@ -50,7 +50,7 @@ func TestUploadHandlerForwardingRawData(t *testing.T) { ...@@ -50,7 +50,7 @@ func TestUploadHandlerForwardingRawData(t *testing.T) {
response := httptest.NewRecorder() response := httptest.NewRecorder()
httpRequest.Header.Set("Gitlab-Workhorse-Temp-Path", tempPath) httpRequest.Header.Set(tempPathHeader, tempPath)
u := newUpstream(ts.URL, nil) u := newUpstream(ts.URL, nil)
u.handleFileUploads(response, httpRequest) u.handleFileUploads(response, httpRequest)
...@@ -124,7 +124,7 @@ func TestUploadHandlerRewritingMultiPartData(t *testing.T) { ...@@ -124,7 +124,7 @@ func TestUploadHandlerRewritingMultiPartData(t *testing.T) {
httpRequest.Body = ioutil.NopCloser(&buffer) httpRequest.Body = ioutil.NopCloser(&buffer)
httpRequest.ContentLength = int64(buffer.Len()) httpRequest.ContentLength = int64(buffer.Len())
httpRequest.Header.Set("Content-Type", writer.FormDataContentType()) httpRequest.Header.Set("Content-Type", writer.FormDataContentType())
httpRequest.Header.Set("Gitlab-Workhorse-Temp-Path", tempPath) httpRequest.Header.Set(tempPathHeader, tempPath)
response := httptest.NewRecorder() response := httptest.NewRecorder()
u := newUpstream(ts.URL, nil) u := newUpstream(ts.URL, nil)
......
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