aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRoger Peppe <rogpeppe@gmail.com>2012-01-26 16:50:56 +0000
committerRoger Peppe <rogpeppe@gmail.com>2012-01-26 16:50:56 +0000
commit32d7a7364f10b652c36e1515623586d0db82ef20 (patch)
tree3014bc54f658df2ba122f633980b7d549ae9885e
parent974fa755573cbcad4e6ff48e4faae25ffa2cca43 (diff)
downloadgo-32d7a7364f10b652c36e1515623586d0db82ef20.tar.gz
go-32d7a7364f10b652c36e1515623586d0db82ef20.zip
net/http: make ParseForm ignore unknown content types.
Also fix a shadowed error variable bug. R=golang-dev, rsc CC=golang-dev https://golang.org/cl/5573072
-rw-r--r--src/pkg/net/http/request.go4
-rw-r--r--src/pkg/net/http/request_test.go19
2 files changed, 12 insertions, 11 deletions
diff --git a/src/pkg/net/http/request.go b/src/pkg/net/http/request.go
index 554ad26b2c..59fe0bf9ed 100644
--- a/src/pkg/net/http/request.go
+++ b/src/pkg/net/http/request.go
@@ -606,7 +606,7 @@ func (r *Request) ParseForm() (err error) {
return errors.New("missing form body")
}
ct := r.Header.Get("Content-Type")
- ct, _, err := mime.ParseMediaType(ct)
+ ct, _, err = mime.ParseMediaType(ct)
switch {
case ct == "application/x-www-form-urlencoded":
var reader io.Reader = r.Body
@@ -646,8 +646,6 @@ func (r *Request) ParseForm() (err error) {
// Clean this up and write more tests.
// request_test.go contains the start of this,
// in TestRequestMultipartCallOrder.
- default:
- return &badStringError{"unknown Content-Type", ct}
}
}
return err
diff --git a/src/pkg/net/http/request_test.go b/src/pkg/net/http/request_test.go
index 7b78645169..7a3556d036 100644
--- a/src/pkg/net/http/request_test.go
+++ b/src/pkg/net/http/request_test.go
@@ -46,19 +46,19 @@ func TestPostQuery(t *testing.T) {
type stringMap map[string][]string
type parseContentTypeTest struct {
+ shouldError bool
contentType stringMap
}
var parseContentTypeTests = []parseContentTypeTest{
- {contentType: stringMap{"Content-Type": {"text/plain"}}},
- {contentType: stringMap{}}, // Non-existent keys are not placed. The value nil is illegal.
- {contentType: stringMap{"Content-Type": {"text/plain; boundary="}}},
- {
- contentType: stringMap{"Content-Type": {"application/unknown"}},
- },
+ {false, stringMap{"Content-Type": {"text/plain"}}},
+ // Non-existent keys are not placed. The value nil is illegal.
+ {true, stringMap{}},
+ {true, stringMap{"Content-Type": {"text/plain; boundary="}}},
+ {false, stringMap{"Content-Type": {"application/unknown"}}},
}
-func TestParseFormBadContentType(t *testing.T) {
+func TestParseFormUnknownContentType(t *testing.T) {
for i, test := range parseContentTypeTests {
req := &Request{
Method: "POST",
@@ -66,8 +66,11 @@ func TestParseFormBadContentType(t *testing.T) {
Body: ioutil.NopCloser(bytes.NewBufferString("body")),
}
err := req.ParseForm()
- if err == nil {
+ switch {
+ case err == nil && test.shouldError:
t.Errorf("test %d should have returned error", i)
+ case err != nil && !test.shouldError:
+ t.Errorf("test %d should not have returned error, got %v", i, err)
}
}
}