mirror of
https://github.com/golang/go
synced 2024-11-22 03:34:40 -07:00
Fixing HTTP POST handling to work with Chrome and Safari.
request.go does not handle Content-Type correctly for the definition of Media Types. http://www.w3.org/Protocols/rfc2616/rfc2616-sec3.html#sec3.7 R=rsc APPROVED=rsc DELTA=44 (42 added, 0 deleted, 2 changed) OCL=35274 CL=35306
This commit is contained in:
parent
11d3805579
commit
41a2b21f26
@ -627,7 +627,7 @@ func (r *Request) ParseForm() (err os.Error) {
|
||||
return os.ErrorString("missing form body")
|
||||
}
|
||||
ct, _ := r.Header["Content-Type"];
|
||||
switch ct {
|
||||
switch strings.Split(ct, ";", 2)[0] {
|
||||
case "text/plain", "application/x-www-form-urlencoded", "":
|
||||
var b []byte;
|
||||
if b, err = io.ReadAll(r.Body); err != nil {
|
||||
|
@ -4,7 +4,10 @@
|
||||
|
||||
package http
|
||||
|
||||
import "testing"
|
||||
import (
|
||||
"bytes";
|
||||
"testing";
|
||||
)
|
||||
|
||||
type stringMultimap map[string] []string
|
||||
|
||||
@ -64,3 +67,42 @@ func TestQuery(t *testing.T) {
|
||||
t.Errorf(`req.FormValue("q") = %q, want "foo"`, q);
|
||||
}
|
||||
}
|
||||
|
||||
type stringMap map[string]string
|
||||
type parseContentTypeTest struct {
|
||||
contentType stringMap;
|
||||
error bool;
|
||||
}
|
||||
|
||||
var parseContentTypeTests = []parseContentTypeTest{
|
||||
parseContentTypeTest{
|
||||
contentType: stringMap{ "Content-Type": "text/plain" },
|
||||
},
|
||||
parseContentTypeTest{
|
||||
contentType: stringMap{ "Content-Type": "" },
|
||||
},
|
||||
parseContentTypeTest{
|
||||
contentType: stringMap{ "Content-Type": "text/plain; boundary=" },
|
||||
},
|
||||
parseContentTypeTest{
|
||||
contentType: stringMap{ "Content-Type": "application/unknown" },
|
||||
error: true,
|
||||
},
|
||||
}
|
||||
|
||||
func TestPostContentTypeParsing(t *testing.T) {
|
||||
for i, test := range parseContentTypeTests {
|
||||
req := &Request{
|
||||
Method: "POST",
|
||||
Header: test.contentType,
|
||||
Body: bytes.NewBufferString("body")
|
||||
};
|
||||
err := req.ParseForm();
|
||||
if !test.error && err != nil {
|
||||
t.Errorf("test %d: Unexpected error: %v", i, err);
|
||||
}
|
||||
if test.error && err == nil {
|
||||
t.Errorf("test %d should have returned error", i);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user