Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

net/http: make Request.Form.Get call ParseForm automatically #24338

Closed
Trion129 opened this issue Mar 10, 2018 · 4 comments

Comments

Projects
None yet
4 participants
@Trion129
Copy link

commented Mar 10, 2018

req.ParseForm() is needed to be called before accessing the form parameters using param := req.Form.Get("param-name") where req is a http.Request

Is there a reason behind this?
I would like to add a feature to ParseForm automatically from Form.Get() on first execution and on next calls, check if Form is already parsed and work as usual.
What are your thoughts?

@mvdan

This comment has been minimized.

Copy link
Member

commented Mar 10, 2018

How exactly would this work? r.Form is of type url.Values, so it can't possibly make a call back to http.Request - that would mean an import cycle.

@mvdan mvdan changed the title http.Request.Form.Get can ParseForm automatically net/http: make Request.Form.Get call ParseForm automatically Mar 10, 2018

@mvdan mvdan added the NeedsDecision label Mar 10, 2018

@pciet

This comment has been minimized.

Copy link
Contributor

commented Mar 10, 2018

This functionality is already implemented in one way as r.FormValue but the parse error is ignored and multiple values for a key isn't handled (POST/PUT body parameters take precedence over URL query values, and the first value is picked).

// Go 2 improvement?
func (r *Request) FormValue(key string) ([]string, error)

Go 2 net/http improvements: #5465

@Trion129

This comment has been minimized.

Copy link
Author

commented Mar 10, 2018

Ah, I didn't know about r.FormValue 😋 That is indeed what I need! Most of form tutorials were using Parse and then Form.Get, so I thought maybe it doesn't exist.
What about an alias GetFormValue? because first time I tried to find the function in my IDE, I typed req.Get in hopes something like this will show up.

@mvdan

This comment has been minimized.

Copy link
Member

commented Mar 10, 2018

Go2 changes are already being tracked in another issue, so I'm going to close this one.

Exposing the same method under two names is a bad idea in my opinion; especially since Go tends to not like getters: https://golang.org/doc/effective_go.html#Getters

@mvdan mvdan closed this Mar 10, 2018

@golang golang locked and limited conversation to collaborators Mar 10, 2019

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
You can’t perform that action at this time.