From 08ce026f52f9fd65b49d99745dffed46a3951585 Mon Sep 17 00:00:00 2001 From: OneOfOne Date: Wed, 21 Feb 2018 21:58:17 +0200 Subject: [PATCH] fix the logic for checking multipart/mixed and add a test --- src/net/http/request.go | 2 +- src/net/http/request_test.go | 10 ++++++++++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/src/net/http/request.go b/src/net/http/request.go index 26da7adc25..1eb6d39067 100644 --- a/src/net/http/request.go +++ b/src/net/http/request.go @@ -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"] diff --git a/src/net/http/request_test.go b/src/net/http/request_test.go index fa716ee59d..aaf9d5cb9b 100644 --- a/src/net/http/request_test.go +++ b/src/net/http/request_test.go @@ -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 {