// "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)
"bytes"
"encoding/json"
"io"
+ "mime/multipart"
"net/http"
"net/http/httptest"
"net/url"
}
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 {
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()