From 31fa584906469b494e9e887ed1cc4612e4349649 Mon Sep 17 00:00:00 2001 From: Brad Fitzpatrick Date: Wed, 10 Aug 2011 08:08:53 -0700 Subject: [PATCH] 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 --- src/pkg/http/request.go | 6 +++--- src/pkg/http/request_test.go | 12 ++++++++++++ 2 files changed, 15 insertions(+), 3 deletions(-) diff --git a/src/pkg/http/request.go b/src/pkg/http/request.go index a1c98a1f8fa..7aae8b4235a 100644 --- a/src/pkg/http/request.go +++ b/src/pkg/http/request.go @@ -729,6 +729,9 @@ func (r *Request) ParseForm() (err os.Error) { // ParseMultipartForm calls ParseForm if necessary. // After one call to ParseMultipartForm, subsequent calls have no effect. func (r *Request) ParseMultipartForm(maxMemory int64) os.Error { + if r.MultipartForm == multipartByReader { + return os.NewError("http: multipart handled by MultipartReader") + } if r.Form == nil { err := r.ParseForm() if err != nil { @@ -738,9 +741,6 @@ func (r *Request) ParseMultipartForm(maxMemory int64) os.Error { if r.MultipartForm != nil { return nil } - if r.MultipartForm == multipartByReader { - return os.NewError("http: multipart handled by MultipartReader") - } mr, err := r.multipartReader() if err == ErrNotMultipart { diff --git a/src/pkg/http/request_test.go b/src/pkg/http/request_test.go index e03ed3b053a..b5482db38b3 100644 --- a/src/pkg/http/request_test.go +++ b/src/pkg/http/request_test.go @@ -219,6 +219,18 @@ func TestEmptyMultipartRequest(t *testing.T) { 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) { f, fh, err := req.FormFile("missing") if f != nil {