Skip to content

net/http: r.FormValue() ignores the return value of ParseMultipartForm() #20895

@saleemjaffer

Description

@saleemjaffer

Please answer these questions before submitting your issue. Thanks!

What version of Go are you using (go version)?

go version go1.8.1 darwin/amd64

What operating system and processor architecture are you using (go env)?

GOARCH="amd64"
GOBIN=""
GOEXE=""
GOHOSTARCH="amd64"
GOHOSTOS="darwin"
GOOS="darwin"
GOPATH="/Users/saleem/proj"
GORACE=""
GOROOT="/usr/local/Cellar/go/1.8.1/libexec"
GOTOOLDIR="/usr/local/Cellar/go/1.8.1/libexec/pkg/tool/darwin_amd64"
GCCGO="gccgo"
CC="clang"
GOGCCFLAGS="-fPIC -m64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fdebug-prefix-map=/var/folders/tx/9dlgzqg11c30qh8p6l3czn000000gn/T/go-build451820530=/tmp/go-build -gno-record-gcc-switches -fno-common"
CXX="clang++"
CGO_ENABLED="1"
PKG_CONFIG="pkg-config"
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"

What did you do?

I have a Go Http endpoint that handles image uploads. From the client I make a POST request, with a content type multipart/form-data. I send some string key, value pairs and an image file.

On the server when I try to read the string values sent using request.FormValue("key_name") I get an empty string. This is the source code of request.FormValue from net/http:

func (r *Request) FormValue(key string) string {
	if r.Form == nil {
		r.ParseMultipartForm(defaultMaxMemory)
	}
	if vs := r.Form[key]; len(vs) > 0 {
		return vs[0]
	}
	return ""
}

The return value of ParseMultipartForm is ignored. It is the ParseMultipartForm function which is failing. Why is the return value ignored?

What did you expect to see?

The error returned from ParseMultipartForm should have been handled in request.FormValue of the net/http package

What did you see instead?

The error returned from ParseMultipartForm is not handled.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions