Commit 57e27a87 authored by Jakub Ryszard Czarnowicz's avatar Jakub Ryszard Czarnowicz Committed by Brad Fitzpatrick

net/http: empty contenty-type treated as application/octet-stream

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
parent 0e97f418
...@@ -673,6 +673,11 @@ func parsePostForm(r *Request) (vs url.Values, err error) { ...@@ -673,6 +673,11 @@ func parsePostForm(r *Request) (vs url.Values, err error) {
return return
} }
ct := r.Header.Get("Content-Type") 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) ct, _, err = mime.ParseMediaType(ct)
switch { switch {
case ct == "application/x-www-form-urlencoded": case ct == "application/x-www-form-urlencoded":
......
...@@ -68,8 +68,9 @@ type parseContentTypeTest struct { ...@@ -68,8 +68,9 @@ type parseContentTypeTest struct {
var parseContentTypeTests = []parseContentTypeTest{ var parseContentTypeTests = []parseContentTypeTest{
{false, stringMap{"Content-Type": {"text/plain"}}}, {false, stringMap{"Content-Type": {"text/plain"}}},
// Non-existent keys are not placed. The value nil is illegal. // Empty content type is legal - shoult be treated as
{true, stringMap{}}, // application/octet-stream (RFC 2616, section 7.2.1)
{false, stringMap{}},
{true, stringMap{"Content-Type": {"text/plain; boundary="}}}, {true, stringMap{"Content-Type": {"text/plain; boundary="}}},
{false, stringMap{"Content-Type": {"application/unknown"}}}, {false, stringMap{"Content-Type": {"application/unknown"}}},
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment