]> Cypherpunks repositories - gostls13.git/commitdiff
net/http: empty contenty-type treated as application/octet-stream
authorJakub Ryszard Czarnowicz <j.czarnowicz@gmail.com>
Fri, 20 Dec 2013 19:49:42 +0000 (11:49 -0800)
committerBrad Fitzpatrick <bradfitz@golang.org>
Fri, 20 Dec 2013 19:49:42 +0000 (11:49 -0800)
RFC 2616, section 7.2.1 - empty type SHOULD be treated as
application/octet-stream.
Fixes #6616.

R=golang-codereviews, gobot, bradfitz, josharian
CC=golang-codereviews
https://golang.org/cl/31810043

src/pkg/net/http/request.go
src/pkg/net/http/request_test.go

index 7702d320c7baa796795f8a30330c80263030de5f..6ed21af568e5e9b0d66abc1da978d96e440023a4 100644 (file)
@@ -673,6 +673,11 @@ func parsePostForm(r *Request) (vs url.Values, err error) {
                return
        }
        ct := r.Header.Get("Content-Type")
+       // RFC 2616, section 7.2.1 - empty type
+       //   SHOULD be treated as application/octet-stream
+       if ct == "" {
+               ct = "application/octet-stream"
+       }
        ct, _, err = mime.ParseMediaType(ct)
        switch {
        case ct == "application/x-www-form-urlencoded":
index 89303c33602017b12328f0fac54926a654cff59e..17af781c9dbfaed5874ba9229a6b07c2d7e5797a 100644 (file)
@@ -68,8 +68,9 @@ type parseContentTypeTest struct {
 
 var parseContentTypeTests = []parseContentTypeTest{
        {false, stringMap{"Content-Type": {"text/plain"}}},
-       // Non-existent keys are not placed. The value nil is illegal.
-       {true, stringMap{}},
+       // Empty content type is legal - shoult be treated as
+       // application/octet-stream (RFC 2616, section 7.2.1)
+       {false, stringMap{}},
        {true, stringMap{"Content-Type": {"text/plain; boundary="}}},
        {false, stringMap{"Content-Type": {"application/unknown"}}},
 }