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: (*Request) ParseForm: document the error condition #20988

Open
kevinburke opened this issue Jul 12, 2017 · 4 comments
Open

net/http: (*Request) ParseForm: document the error condition #20988

kevinburke opened this issue Jul 12, 2017 · 4 comments

Comments

@kevinburke
Copy link
Contributor

The current documentation for ParseForm doesn't describe when an error can be returned:

ParseForm populates r.Form and r.PostForm.

For all requests, ParseForm parses the raw query from the URL and updates r.Form.

For POST, PUT, and PATCH requests, it also parses the request body as a form and puts the results into both r.PostForm and r.Form. Request body parameters take precedence over URL query string values in r.Form.

For other HTTP methods, or when the Content-Type is not application/x-www-form-urlencoded, the request Body is not read, and r.PostForm is initialized to a non-nil, empty value.

If the request Body's size has not already been limited by MaxBytesReader, the size is capped at 10MB.

ParseMultipartForm calls ParseForm automatically. ParseForm is idempotent.

https://godoc.org/net/http#Request.ParseForm

@bradfitz bradfitz added this to the Go1.10 milestone Jul 14, 2017
@gopherbot
Copy link

CL https://golang.org/cl/48890 mentions this issue.

@bradfitz
Copy link
Contributor

Why is this API unique in its need to enumerate all the possible ways an error might be returned?

We don't do that elsewhere. If anything, we documented guaranteed error types or error values in places, but we rarely say "if X happens, an error will be returned"

@kevinburke
Copy link
Contributor Author

I guess I was just sort of surprised that parsing could return an error and was wondering what condition the form parser could hit that would result in an error. In some cases oddities in parsing just result in setting the resulting url.Values to the empty string, or setting an empty value. It turns out one occurs if r.Body is nil or if a percent sign is not accompanied by a URL-unescapable value.

@dndungu
Copy link
Contributor

dndungu commented Jul 27, 2019

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants