[arvados] created: 2.1.0-3219-g674256000

git repository hosting git at public.arvados.org
Wed Dec 21 19:32:17 UTC 2022


        at  6742560001ba1db4d51e5bcd5333a0b04d07ca5c (commit)


commit 6742560001ba1db4d51e5bcd5333a0b04d07ca5c
Author: Tom Clegg <tom at curii.com>
Date:   Wed Dec 21 14:31:26 2022 -0500

    19597: Parse multipart/form-data request body.
    
    Arvados-DCO-1.1-Signed-off-by: Tom Clegg <tom at curii.com>

diff --git a/lib/controller/router/request.go b/lib/controller/router/request.go
index 31f2e1d7b..c0a2f23cc 100644
--- a/lib/controller/router/request.go
+++ b/lib/controller/router/request.go
@@ -62,6 +62,12 @@ func guessAndParse(k, v string) (interface{}, error) {
 // "collection"), it is renamed to "attrs".
 func (rtr *router) loadRequestParams(req *http.Request, attrsKey string) (map[string]interface{}, error) {
 	err := req.ParseForm()
+	if err == nil {
+		err = req.ParseMultipartForm(int64(rtr.config.MaxRequestSize))
+		if err == http.ErrNotMultipart {
+			err = nil
+		}
+	}
 	if err != nil {
 		if err.Error() == "http: request body too large" {
 			return nil, httpError(http.StatusRequestEntityTooLarge, err)
diff --git a/lib/controller/router/request_test.go b/lib/controller/router/request_test.go
index 4544a6bb6..82f1fb8e8 100644
--- a/lib/controller/router/request_test.go
+++ b/lib/controller/router/request_test.go
@@ -8,6 +8,7 @@ import (
 	"bytes"
 	"encoding/json"
 	"io"
+	"mime/multipart"
 	"net/http"
 	"net/http/httptest"
 	"net/url"
@@ -116,7 +117,7 @@ func (tr *testReq) Request() *http.Request {
 	}
 	if tr.json {
 		req.Header.Set("Content-Type", "application/json")
-	} else {
+	} else if tr.header.Get("Content-Type") == "" {
 		req.Header.Set("Content-Type", "application/x-www-form-urlencoded")
 	}
 	for k, v := range tr.header {
@@ -131,11 +132,18 @@ func (tr *testReq) bodyContent() string {
 
 func (s *RouterSuite) TestAttrsInBody(c *check.C) {
 	attrs := map[string]interface{}{"foo": "bar"}
+
+	multipartBody := new(bytes.Buffer)
+	multipartWriter := multipart.NewWriter(multipartBody)
+	multipartWriter.WriteField("attrs", `{"foo":"bar"}`)
+	multipartWriter.Close()
+
 	for _, tr := range []testReq{
 		{attrsKey: "model_name", json: true, attrs: attrs},
 		{attrsKey: "model_name", json: true, attrs: attrs, jsonAttrsTop: true},
 		{attrsKey: "model_name", json: true, attrs: attrs, jsonAttrsTop: true, jsonStringParam: true},
 		{attrsKey: "model_name", json: true, attrs: attrs, jsonAttrsTop: false, jsonStringParam: true},
+		{body: multipartBody, header: http.Header{"Content-Type": []string{multipartWriter.FormDataContentType()}}},
 	} {
 		c.Logf("tr: %#v", tr)
 		req := tr.Request()

-----------------------------------------------------------------------


hooks/post-receive
-- 




More information about the arvados-commits mailing list