diff options
| author | Brad Fitzpatrick <bradfitz@golang.org> | 2011-08-18 12:51:23 -0700 |
|---|---|---|
| committer | Brad Fitzpatrick <bradfitz@golang.org> | 2011-08-18 12:51:23 -0700 |
| commit | a986d98053a817600509b2c0088e1cf118cf573a (patch) | |
| tree | 87e2c265aa261277b8090c785f26481473066233 /src/pkg/http | |
| parent | 88432625998cf6c05bacc86ef9d29c25e0c608c8 (diff) | |
| download | go-a986d98053a817600509b2c0088e1cf118cf573a.tar.xz | |
mime: ParseMediaType returns os.Error now, not a nil map
ParseMediaType previously documented that it always returned
a non-nil map, but also documented that it returned a nil map
to signal an error.
That is confusing, contradictory and not Go-like.
Now it returns (mediatype string, params map, os.Error).
R=golang-dev, r
CC=golang-dev
https://golang.org/cl/4867054
Diffstat (limited to 'src/pkg/http')
| -rw-r--r-- | src/pkg/http/request.go | 18 |
1 files changed, 12 insertions, 6 deletions
diff --git a/src/pkg/http/request.go b/src/pkg/http/request.go index ed41fa45c1..d45de8e2e4 100644 --- a/src/pkg/http/request.go +++ b/src/pkg/http/request.go @@ -234,8 +234,8 @@ func (r *Request) multipartReader() (*multipart.Reader, os.Error) { if v == "" { return nil, ErrNotMultipart } - d, params := mime.ParseMediaType(v) - if d != "multipart/form-data" { + d, params, err := mime.ParseMediaType(v) + if err != nil || d != "multipart/form-data" { return nil, ErrNotMultipart } boundary, ok := params["boundary"] @@ -625,8 +625,9 @@ func (r *Request) ParseForm() (err os.Error) { return os.NewError("missing form body") } ct := r.Header.Get("Content-Type") - switch strings.SplitN(ct, ";", 2)[0] { - case "text/plain", "application/x-www-form-urlencoded", "": + ct, _, err := mime.ParseMediaType(ct) + switch { + case ct == "text/plain" || ct == "application/x-www-form-urlencoded" || ct == "": const maxFormSize = int64(10 << 20) // 10 MB is a lot of text. b, e := ioutil.ReadAll(io.LimitReader(r.Body, maxFormSize+1)) if e != nil { @@ -652,8 +653,13 @@ func (r *Request) ParseForm() (err os.Error) { r.Form.Add(k, value) } } - case "multipart/form-data": - // handled by ParseMultipartForm + case ct == "multipart/form-data": + // handled by ParseMultipartForm (which is calling us, or should be) + // TODO(bradfitz): there are too many possible + // orders to call too many functions here. + // Clean this up and write more tests. + // request_test.go contains the start of this, + // in TestRequestMultipartCallOrder. default: return &badStringError{"unknown Content-Type", ct} } |
