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