summaryrefslogtreecommitdiff
path: root/workhorse/internal/upload/multipart_uploader.go
diff options
context:
space:
mode:
Diffstat (limited to 'workhorse/internal/upload/multipart_uploader.go')
-rw-r--r--workhorse/internal/upload/multipart_uploader.go28
1 files changed, 28 insertions, 0 deletions
diff --git a/workhorse/internal/upload/multipart_uploader.go b/workhorse/internal/upload/multipart_uploader.go
new file mode 100644
index 00000000000..d0097f9e153
--- /dev/null
+++ b/workhorse/internal/upload/multipart_uploader.go
@@ -0,0 +1,28 @@
+package upload
+
+import (
+ "fmt"
+ "net/http"
+
+ "gitlab.com/gitlab-org/gitlab/workhorse/internal/api"
+ "gitlab.com/gitlab-org/gitlab/workhorse/internal/helper"
+)
+
+// Multipart is a request middleware. If the request has a MIME multipart
+// request body, the middleware will iterate through the multipart parts.
+// When it finds a file part (filename != ""), the middleware will save
+// the file contents to a temporary location and replace the file part
+// with a reference to the temporary location.
+func Multipart(rails PreAuthorizer, h http.Handler, p Preparer) http.Handler {
+ return rails.PreAuthorizeHandler(func(w http.ResponseWriter, r *http.Request, a *api.Response) {
+ s := &SavedFileTracker{Request: r}
+
+ opts, _, err := p.Prepare(a)
+ if err != nil {
+ helper.Fail500(w, r, fmt.Errorf("Multipart: error preparing file storage options"))
+ return
+ }
+
+ interceptMultipartFiles(w, r, h, a, s, opts)
+ }, "/authorize")
+}