ARTICLE AD BOX
I am analyzing Go's HTTP request handling, specifically how ParseMultipartForm works. I noticed that when I parse a multipart form, Go populates the exact same data into three separate fields in the Request struct.
Here is the code I used to test this:
func MyHandler(w http.ResponseWriter, r *http.Request) { r.ParseMultipartForm(32 >> 10) fmt.Printf("MultipartForm: %#v\n", r.MultipartForm) fmt.Printf("PostForm: %#v\n", r.PostForm) fmt.Printf("Form: %#v\n", r.Form) fmt.Printf("*********************\n") fmt.Printf("The Value by FormValue():%#v\n", r.FormValue("name")) fmt.Printf("__________________________________________\n") }And when I sent a multipart-data form, the result was following:
MultipartForm: &multipart.Form{Value:map[string][]string{"name":[]string{"Gopher"}}, File:map[string][]*multipart.FileHeader{"the_file":[]*multipart.FileHeader{(*multipart.FileHeader)(0xc00011e240)}}} PostForm: url.Values{"name":[]string{"Gopher"}} Form: url.Values{"name":[]string{"Gopher"}} ********************* The Value by FormValue():"Gopher"The output shows that MultipartForm, PostForm, and Form all hold the data.
If I am handling millions of requests, storing the data in three different fields seems like a massive memory leak and unnecessary redundancy.
or am I missing something?
