Commit 31fa5849 authored by Brad Fitzpatrick's avatar Brad Fitzpatrick

http: fix ParseMultipartForm after MultipartReader error

Addresses part of issue 2093
Thanks to espians....@

R=golang-dev, nigeltao
CC=golang-dev
https://golang.org/cl/4808087
parent 849b54a2
...@@ -729,6 +729,9 @@ func (r *Request) ParseForm() (err os.Error) { ...@@ -729,6 +729,9 @@ func (r *Request) ParseForm() (err os.Error) {
// ParseMultipartForm calls ParseForm if necessary. // ParseMultipartForm calls ParseForm if necessary.
// After one call to ParseMultipartForm, subsequent calls have no effect. // After one call to ParseMultipartForm, subsequent calls have no effect.
func (r *Request) ParseMultipartForm(maxMemory int64) os.Error { func (r *Request) ParseMultipartForm(maxMemory int64) os.Error {
if r.MultipartForm == multipartByReader {
return os.NewError("http: multipart handled by MultipartReader")
}
if r.Form == nil { if r.Form == nil {
err := r.ParseForm() err := r.ParseForm()
if err != nil { if err != nil {
...@@ -738,9 +741,6 @@ func (r *Request) ParseMultipartForm(maxMemory int64) os.Error { ...@@ -738,9 +741,6 @@ func (r *Request) ParseMultipartForm(maxMemory int64) os.Error {
if r.MultipartForm != nil { if r.MultipartForm != nil {
return nil return nil
} }
if r.MultipartForm == multipartByReader {
return os.NewError("http: multipart handled by MultipartReader")
}
mr, err := r.multipartReader() mr, err := r.multipartReader()
if err == ErrNotMultipart { if err == ErrNotMultipart {
......
...@@ -219,6 +219,18 @@ func TestEmptyMultipartRequest(t *testing.T) { ...@@ -219,6 +219,18 @@ func TestEmptyMultipartRequest(t *testing.T) {
testMissingFile(t, req) testMissingFile(t, req)
} }
func TestRequestMultipartCallOrder(t *testing.T) {
req := newTestMultipartRequest(t)
_, err := req.MultipartReader()
if err != nil {
t.Fatalf("MultipartReader: %v", err)
}
err = req.ParseMultipartForm(1024)
if err == nil {
t.Errorf("expected an error from ParseMultipartForm after call to MultipartReader")
}
}
func testMissingFile(t *testing.T, req *Request) { func testMissingFile(t *testing.T, req *Request) {
f, fh, err := req.FormFile("missing") f, fh, err := req.FormFile("missing")
if f != nil { if f != nil {
......
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