aboutsummaryrefslogtreecommitdiff
path: root/src/net/http/client.go
diff options
context:
space:
mode:
authorBrad Fitzpatrick <bradfitz@golang.org>2015-04-27 18:55:21 -0700
committerBrad Fitzpatrick <bradfitz@golang.org>2015-04-28 21:58:58 +0000
commit339cf9807debe2b20e8701ff3821079a8e925700 (patch)
tree4a73c2d646fcf1af00819120f9a1f8c3b4c46c23 /src/net/http/client.go
parentac354ba725c252e988d46a0f616d309f955e26f2 (diff)
downloadgo-339cf9807debe2b20e8701ff3821079a8e925700.tar.xz
net/http: documentation updates
Fixes #10366 (how to set custom headers) Fixes #9836 (PATCH in PostForm) Fixes #9276 (generating a server-side Request for testing) Update #8991 (clarify Response.Write for now; export ReverseProxy's copy later?) Change-Id: I95a11bf3bb3eeeeb72775b6ebfbc761641addc35 Reviewed-on: https://go-review.googlesource.com/9410 Reviewed-by: David Crawshaw <crawshaw@golang.org>
Diffstat (limited to 'src/net/http/client.go')
-rw-r--r--src/net/http/client.go33
1 files changed, 26 insertions, 7 deletions
diff --git a/src/net/http/client.go b/src/net/http/client.go
index 88d444eca2..1c5e1911e0 100644
--- a/src/net/http/client.go
+++ b/src/net/http/client.go
@@ -257,8 +257,9 @@ func shouldRedirectPost(statusCode int) bool {
return false
}
-// Get issues a GET to the specified URL. If the response is one of the following
-// redirect codes, Get follows the redirect, up to a maximum of 10 redirects:
+// Get issues a GET to the specified URL. If the response is one of
+// the following redirect codes, Get follows the redirect, up to a
+// maximum of 10 redirects:
//
// 301 (Moved Permanently)
// 302 (Found)
@@ -273,11 +274,14 @@ func shouldRedirectPost(statusCode int) bool {
// Caller should close resp.Body when done reading from it.
//
// Get is a wrapper around DefaultClient.Get.
+//
+// To make a request with custom headers, use NewRequest and
+// DefaultClient.Do.
func Get(url string) (resp *Response, err error) {
return DefaultClient.Get(url)
}
-// Get issues a GET to the specified URL. If the response is one of the
+// Get issues a GET to the specified URL. If the response is one of the
// following redirect codes, Get follows the redirect after calling the
// Client's CheckRedirect function.
//
@@ -292,6 +296,8 @@ func Get(url string) (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.
+//
+// To make a request with custom headers, use NewRequest and Client.Do.
func (c *Client) Get(url string) (resp *Response, err error) {
req, err := NewRequest("GET", url, nil)
if err != nil {
@@ -438,7 +444,12 @@ func defaultCheckRedirect(req *Request, via []*Request) error {
//
// Caller should close resp.Body when done reading from it.
//
-// Post is a wrapper around DefaultClient.Post
+// If the provided body is an io.Closer, it is closed after the
+// request.
+//
+// Post is a wrapper around DefaultClient.Post.
+//
+// To set custom headers, use NewRequest and DefaultClient.Do.
func Post(url string, bodyType string, body io.Reader) (resp *Response, err error) {
return DefaultClient.Post(url, bodyType, body)
}
@@ -447,8 +458,10 @@ func Post(url string, bodyType string, body io.Reader) (resp *Response, err erro
//
// Caller should close resp.Body when done reading from it.
//
-// If the provided body is also an io.Closer, it is closed after the
+// If the provided body is an io.Closer, it is closed after the
// request.
+//
+// To set custom headers, use NewRequest and Client.Do.
func (c *Client) Post(url string, bodyType string, body io.Reader) (resp *Response, err error) {
req, err := NewRequest("POST", url, body)
if err != nil {
@@ -461,16 +474,22 @@ func (c *Client) Post(url string, bodyType string, body io.Reader) (resp *Respon
// PostForm issues a POST to the specified URL, with data's keys and
// values URL-encoded as the request body.
//
+// The Content-Type header is set to application/x-www-form-urlencoded.
+// To set other headers, use NewRequest and DefaultClient.Do.
+//
// When err is nil, resp always contains a non-nil resp.Body.
// Caller should close resp.Body when done reading from it.
//
-// PostForm is a wrapper around DefaultClient.PostForm
+// PostForm is a wrapper around DefaultClient.PostForm.
func PostForm(url string, data url.Values) (resp *Response, err error) {
return DefaultClient.PostForm(url, data)
}
// PostForm issues a POST to the specified URL,
-// with data's keys and values urlencoded as the request body.
+// with data's keys and values URL-encoded as the request body.
+//
+// The Content-Type header is set to application/x-www-form-urlencoded.
+// To set other headers, use NewRequest and DefaultClient.Do.
//
// When err is nil, resp always contains a non-nil resp.Body.
// Caller should close resp.Body when done reading from it.