1
0
mirror of https://github.com/golang/go synced 2024-11-14 08:50:22 -07:00

fix the logic for checking multipart/mixed and add a test

This commit is contained in:
OneOfOne 2018-02-21 21:58:17 +02:00
parent 885ff1d9c9
commit 08ce026f52
No known key found for this signature in database
GPG Key ID: F3A4E8B6760B7805
2 changed files with 11 additions and 1 deletions

View File

@ -431,7 +431,7 @@ func (r *Request) multipartReader(allowMixed bool) (*multipart.Reader, error) {
return nil, ErrNotMultipart
}
d, params, err := mime.ParseMediaType(v)
if err != nil || d != "multipart/form-data" || (allowMixed && d != "multipart/mixed") {
if err != nil || !(d == "multipart/form-data" || allowMixed && d == "multipart/mixed") {
return nil, ErrNotMultipart
}
boundary, ok := params["boundary"]

View File

@ -143,6 +143,16 @@ func TestMultipartReader(t *testing.T) {
t.Errorf("expected multipart; error: %v", err)
}
req = &Request{
Method: "POST",
Header: Header{"Content-Type": {`multipart/mixed; boundary="foo123"`}},
Body: ioutil.NopCloser(new(bytes.Buffer)),
}
multipart, err = req.MultipartReader()
if multipart == nil {
t.Errorf("expected multipart; error: %v", err)
}
req.Header = Header{"Content-Type": {"text/plain"}}
multipart, err = req.MultipartReader()
if multipart != nil {