Skip to content

net/http: the server-side parse form returns inaccurate error #74955

@shvc

Description

@shvc

Go version

go1.24.6

Output of go env in your module/workspace:

GOVERSION="go1.24.6"

What did you do?

Run the following code

package main

import (
	"fmt"
	"net/http"

	"net/http/httptest"
)

func handler(w http.ResponseWriter, r *http.Request) {
	fmt.Printf("r.Body: %#v\n", r.Body)
	err := r.ParseMultipartForm(1024)
	if err != nil {
		fmt.Println("r.ParseMultipartForm error:", err)
		w.WriteHeader(500)
	}
}

func main() {
	req := httptest.NewRequest(http.MethodPost, "http://localhost/upload", nil)
	req.Header.Set("Content-Type", "multipart/form-data;boundary=-----TEST")
	fmt.Printf("req.Body: %#v\n", req.Body)
	w := httptest.NewRecorder()
	handler(w, req)
	resp := w.Result()
	fmt.Println("response code:", resp.StatusCode)
}

I created a http POST form request without body

What did you see happen?

req.Body: http.noBody{}
r.Body: http.noBody{}
r.ParseMultipartForm error: multipart: NextPart: EOF
response code: 500

What did you expect to see?

req.Body: http.noBody{}
r.Body: http.noBody{}
r.ParseMultipartForm error: missing form body
response code: 500

Metadata

Metadata

Assignees

No one assigned

    Labels

    FixPendingIssues that have a fix which has not yet been reviewed or submitted.NeedsInvestigationSomeone must examine and confirm this is a valid issue and not a duplicate of an existing one.

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions