diff options
| author | Brad Fitzpatrick <bradfitz@golang.org> | 2016-12-20 17:59:37 +0000 |
|---|---|---|
| committer | Brad Fitzpatrick <bradfitz@golang.org> | 2016-12-20 18:36:49 +0000 |
| commit | 2eae691d56125c62e0e5f0e4a3bd42e67e423f01 (patch) | |
| tree | 8a52565afef2a88b27ef57ba60d8cf0c6de31ef1 /src/net/http/client.go | |
| parent | 8df54c92c0d442d8de2887aa0e508c9072cce131 (diff) | |
| download | go-2eae691d56125c62e0e5f0e4a3bd42e67e423f01.tar.xz | |
net/http, doc: more redirect documentation
Updates #18347
Updates #9348
Change-Id: I115203b0be3eb2e7e269ff28e2f3c47eeca86038
Reviewed-on: https://go-review.googlesource.com/34657
Reviewed-by: Russ Cox <rsc@golang.org>
Diffstat (limited to 'src/net/http/client.go')
| -rw-r--r-- | src/net/http/client.go | 21 |
1 files changed, 21 insertions, 0 deletions
diff --git a/src/net/http/client.go b/src/net/http/client.go index 9308c5c968..7eb87c6d10 100644 --- a/src/net/http/client.go +++ b/src/net/http/client.go @@ -470,6 +470,15 @@ func redirectBehavior(reqMethod string, resp *Response, via []*Request) (redirec // the returned Response.Body is already closed. // // Generally Get, Post, or PostForm will be used instead of Do. +// +// If the server replies with a redirect, the Client first uses the +// CheckRedirect function to determine whether the redirect should be +// followed. If permitted, a 301, 302, or 303 redirect causes +// subsequent requests to use HTTP method "GET", with no body. +// A 307 or 308 redirect preserves the original HTTP method and body, +// provided that the Request.GetBody function is defined. +// The NewRequest function automatically sets GetBody for common +// standard library body types. func (c *Client) Do(req *Request) (*Response, error) { if req.URL == nil { req.closeBody() @@ -673,6 +682,9 @@ func defaultCheckRedirect(req *Request, via []*Request) error { // Post is a wrapper around DefaultClient.Post. // // To set custom headers, use NewRequest and DefaultClient.Do. +// +// See the Client.Do method documentation for details on how redirects +// are handled. func Post(url string, contentType string, body io.Reader) (resp *Response, err error) { return DefaultClient.Post(url, contentType, body) } @@ -685,6 +697,9 @@ func Post(url string, contentType string, body io.Reader) (resp *Response, err e // request. // // To set custom headers, use NewRequest and Client.Do. +// +// See the Client.Do method documentation for details on how redirects +// are handled. func (c *Client) Post(url string, contentType string, body io.Reader) (resp *Response, err error) { req, err := NewRequest("POST", url, body) if err != nil { @@ -704,6 +719,9 @@ func (c *Client) Post(url string, contentType string, body io.Reader) (resp *Res // Caller should close resp.Body when done reading from it. // // PostForm is a wrapper around DefaultClient.PostForm. +// +// See the Client.Do method documentation for details on how redirects +// are handled. func PostForm(url string, data url.Values) (resp *Response, err error) { return DefaultClient.PostForm(url, data) } @@ -716,6 +734,9 @@ func PostForm(url string, data url.Values) (resp *Response, err error) { // // When err is nil, resp always contains a non-nil resp.Body. // Caller should close resp.Body when done reading from it. +// +// See the Client.Do method documentation for details on how redirects +// are handled. func (c *Client) PostForm(url string, data url.Values) (resp *Response, err error) { return c.Post(url, "application/x-www-form-urlencoded", strings.NewReader(data.Encode())) } |
