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

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions