diff options
Diffstat (limited to 'libgo/go/net/http/client.go')
-rw-r--r-- | libgo/go/net/http/client.go | 39 |
1 files changed, 32 insertions, 7 deletions
diff --git a/libgo/go/net/http/client.go b/libgo/go/net/http/client.go index 88e2028..4d380c6 100644 --- a/libgo/go/net/http/client.go +++ b/libgo/go/net/http/client.go @@ -17,6 +17,7 @@ import ( "fmt" "io" "log" + "net/http/internal/ascii" "net/url" "reflect" "sort" @@ -432,8 +433,7 @@ func basicAuth(username, password string) string { // An error is returned if there were too many redirects or if there // was an HTTP protocol error. A non-2xx response doesn't cause an // error. Any returned error will be of type *url.Error. The url.Error -// value's Timeout method will report true if request timed out or was -// canceled. +// value's Timeout method will report true if the request timed out. // // When err is nil, resp always contains a non-nil resp.Body. // Caller should close resp.Body when done reading from it. @@ -442,6 +442,9 @@ func basicAuth(username, password string) string { // // To make a request with custom headers, use NewRequest and // DefaultClient.Do. +// +// To make a request with a specified context.Context, use NewRequestWithContext +// and DefaultClient.Do. func Get(url string) (resp *Response, err error) { return DefaultClient.Get(url) } @@ -466,6 +469,9 @@ func Get(url string) (resp *Response, err error) { // Caller should close resp.Body when done reading from it. // // To make a request with custom headers, use NewRequest and Client.Do. +// +// To make a request with a specified context.Context, use NewRequestWithContext +// and Client.Do. func (c *Client) Get(url string) (resp *Response, err error) { req, err := NewRequest("GET", url, nil) if err != nil { @@ -541,7 +547,10 @@ func urlErrorOp(method string) string { if method == "" { return "Get" } - return method[:1] + strings.ToLower(method[1:]) + if lowerMethod, ok := ascii.ToLower(method); ok { + return method[:1] + lowerMethod[1:] + } + return method } // Do sends an HTTP request and returns an HTTP response, following @@ -579,8 +588,7 @@ func urlErrorOp(method string) string { // standard library body types. // // Any returned error will be of type *url.Error. The url.Error -// value's Timeout method will report true if request timed out or was -// canceled. +// value's Timeout method will report true if the request timed out. func (c *Client) Do(req *Request) (*Response, error) { return c.do(req) } @@ -719,7 +727,6 @@ func (c *Client) do(req *Request) (retres *Response, reterr error) { reqBodyClosed = true if !deadline.IsZero() && didTimeout() { err = &httpError{ - // TODO: early in cycle: s/Client.Timeout exceeded/timeout or context cancellation/ err: err.Error() + " (Client.Timeout exceeded while awaiting headers)", timeout: true, } @@ -821,6 +828,9 @@ func defaultCheckRedirect(req *Request, via []*Request) error { // // See the Client.Do method documentation for details on how redirects // are handled. +// +// To make a request with a specified context.Context, use NewRequestWithContext +// and DefaultClient.Do. func Post(url, contentType string, body io.Reader) (resp *Response, err error) { return DefaultClient.Post(url, contentType, body) } @@ -834,6 +844,9 @@ func Post(url, contentType string, body io.Reader) (resp *Response, err error) { // // To set custom headers, use NewRequest and Client.Do. // +// To make a request with a specified context.Context, use NewRequestWithContext +// and Client.Do. +// // See the Client.Do method documentation for details on how redirects // are handled. func (c *Client) Post(url, contentType string, body io.Reader) (resp *Response, err error) { @@ -858,6 +871,9 @@ func (c *Client) Post(url, contentType string, body io.Reader) (resp *Response, // // See the Client.Do method documentation for details on how redirects // are handled. +// +// To make a request with a specified context.Context, use NewRequestWithContext +// and DefaultClient.Do. func PostForm(url string, data url.Values) (resp *Response, err error) { return DefaultClient.PostForm(url, data) } @@ -873,6 +889,9 @@ func PostForm(url string, data url.Values) (resp *Response, err error) { // // See the Client.Do method documentation for details on how redirects // are handled. +// +// To make a request with a specified context.Context, use NewRequestWithContext +// and Client.Do. 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())) } @@ -888,6 +907,9 @@ func (c *Client) PostForm(url string, data url.Values) (resp *Response, err erro // 308 (Permanent Redirect) // // Head is a wrapper around DefaultClient.Head +// +// To make a request with a specified context.Context, use NewRequestWithContext +// and DefaultClient.Do. func Head(url string) (resp *Response, err error) { return DefaultClient.Head(url) } @@ -901,6 +923,9 @@ func Head(url string) (resp *Response, err error) { // 303 (See Other) // 307 (Temporary Redirect) // 308 (Permanent Redirect) +// +// To make a request with a specified context.Context, use NewRequestWithContext +// and Client.Do. func (c *Client) Head(url string) (resp *Response, err error) { req, err := NewRequest("HEAD", url, nil) if err != nil { @@ -926,7 +951,7 @@ func (c *Client) CloseIdleConnections() { } // cancelTimerBody is an io.ReadCloser that wraps rc with two features: -// 1) on Read error or close, the stop func is called. +// 1) On Read error or close, the stop func is called. // 2) On Read failure, if reqDidTimeout is true, the error is wrapped and // marked as net.Error that hit its timeout. type cancelTimerBody struct { |