diff options
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 } |