diff options
author | Ondřej Surý <ondrej@sury.org> | 2011-08-03 16:54:30 +0200 |
---|---|---|
committer | Ondřej Surý <ondrej@sury.org> | 2011-08-03 16:54:30 +0200 |
commit | 28592ee1ea1f5cdffcf85472f9de0285d928cf12 (patch) | |
tree | 32944e18b23f7fe4a0818a694aa2a6dfb1835463 /src/pkg/http/client.go | |
parent | e836bee4716dc0d4d913537ad3ad1925a7ac32d0 (diff) | |
download | golang-upstream/59.tar.gz |
Imported Upstream version 59upstream/59
Diffstat (limited to 'src/pkg/http/client.go')
-rw-r--r-- | src/pkg/http/client.go | 14 |
1 files changed, 11 insertions, 3 deletions
diff --git a/src/pkg/http/client.go b/src/pkg/http/client.go index 71b037042..4f63b44f2 100644 --- a/src/pkg/http/client.go +++ b/src/pkg/http/client.go @@ -16,6 +16,11 @@ import ( // A Client is an HTTP client. Its zero value (DefaultClient) is a usable client // that uses DefaultTransport. +// +// The Client's Transport typically has internal state (cached +// TCP connections), so Clients should be reused instead of created as +// needed. Clients are safe for concurrent use by multiple goroutines. +// // Client is not yet very configurable. type Client struct { Transport RoundTripper // if nil, DefaultTransport is used @@ -36,6 +41,9 @@ var DefaultClient = &Client{} // RoundTripper is an interface representing the ability to execute a // single HTTP transaction, obtaining the Response for a given Request. +// +// A RoundTripper must be safe for concurrent use by multiple +// goroutines. type RoundTripper interface { // RoundTrip executes a single HTTP transaction, returning // the Response for the request req. RoundTrip should not @@ -173,7 +181,7 @@ func (c *Client) doFollowingRedirects(ireq *Request) (r *Response, err os.Error) // Add the Referer header. lastReq := via[len(via)-1] if lastReq.URL.Scheme != "https" { - req.Referer = lastReq.URL.String() + req.Header.Set("Referer", lastReq.URL.String()) } err = redirectChecker(req, via) @@ -190,7 +198,7 @@ func (c *Client) doFollowingRedirects(ireq *Request) (r *Response, err os.Error) if shouldRedirect(r.StatusCode) { r.Body.Close() if url = r.Header.Get("Location"); url == "" { - err = os.ErrorString(fmt.Sprintf("%d response missing Location header", r.StatusCode)) + err = os.NewError(fmt.Sprintf("%d response missing Location header", r.StatusCode)) break } base = req.URL @@ -207,7 +215,7 @@ func (c *Client) doFollowingRedirects(ireq *Request) (r *Response, err os.Error) func defaultCheckRedirect(req *Request, via []*Request) os.Error { if len(via) >= 10 { - return os.ErrorString("stopped after 10 redirects") + return os.NewError("stopped after 10 redirects") } return nil } |