mirror of
https://github.com/golang/go
synced 2024-09-25 01:20:13 -06:00
net/http: clarify docs of ParseForm and mention ParseForm in docs for FormValue
while we're at it, also fix a return value stutter in ParseForm. R=bradfitz CC=golang-dev https://golang.org/cl/6847074
This commit is contained in:
parent
4047f300c9
commit
62f54e1294
@ -643,16 +643,20 @@ func parsePostForm(r *Request) (vs url.Values, err error) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// ParseForm parses the raw query from the URL.
|
// ParseForm parses the raw query from the URL and updates r.Form.
|
||||||
|
//
|
||||||
|
// For POST or PUT requests, it also parses the request body as a form and
|
||||||
|
// put the results into both r.PostForm and r.Form.
|
||||||
|
// POST and PUT body parameters take precedence over URL query string values
|
||||||
|
// in r.Form.
|
||||||
//
|
//
|
||||||
// For POST or PUT requests, it also parses the request body as a form.
|
|
||||||
// POST and PUT body parameters take precedence over URL query string values.
|
|
||||||
// If the request Body's size has not already been limited by MaxBytesReader,
|
// If the request Body's size has not already been limited by MaxBytesReader,
|
||||||
// the size is capped at 10MB.
|
// the size is capped at 10MB.
|
||||||
//
|
//
|
||||||
// ParseMultipartForm calls ParseForm automatically.
|
// ParseMultipartForm calls ParseForm automatically.
|
||||||
// It is idempotent.
|
// It is idempotent.
|
||||||
func (r *Request) ParseForm() (err error) {
|
func (r *Request) ParseForm() error {
|
||||||
|
var err error
|
||||||
if r.PostForm == nil {
|
if r.PostForm == nil {
|
||||||
if r.Method == "POST" || r.Method == "PUT" {
|
if r.Method == "POST" || r.Method == "PUT" {
|
||||||
r.PostForm, err = parsePostForm(r)
|
r.PostForm, err = parsePostForm(r)
|
||||||
@ -728,6 +732,7 @@ func (r *Request) ParseMultipartForm(maxMemory int64) error {
|
|||||||
// FormValue returns the first value for the named component of the query.
|
// FormValue returns the first value for the named component of the query.
|
||||||
// POST and PUT body parameters take precedence over URL query string values.
|
// POST and PUT body parameters take precedence over URL query string values.
|
||||||
// FormValue calls ParseMultipartForm and ParseForm if necessary.
|
// FormValue calls ParseMultipartForm and ParseForm if necessary.
|
||||||
|
// To access multiple values of the same key use ParseForm.
|
||||||
func (r *Request) FormValue(key string) string {
|
func (r *Request) FormValue(key string) string {
|
||||||
if r.Form == nil {
|
if r.Form == nil {
|
||||||
r.ParseMultipartForm(defaultMaxMemory)
|
r.ParseMultipartForm(defaultMaxMemory)
|
||||||
|
Loading…
Reference in New Issue
Block a user