~ubuntu-branches/ubuntu/vivid/golang/vivid

« back to all changes in this revision

Viewing changes to src/pkg/http/client.go

  • Committer: Bazaar Package Importer
  • Author(s): Ondřej Surý
  • Date: 2011-08-03 17:04:59 UTC
  • mfrom: (14.1.2 sid)
  • Revision ID: james.westby@ubuntu.com-20110803170459-wzd99m3567y80ila
Tags: 1:59-1
* Imported Upstream version 59
* Refresh patches to a new release
* Fix FTBFS on ARM (Closes: #634270)
* Update version.bash to work with Debian packaging and not hg
  repository

Show diffs side-by-side

added added

removed removed

Lines of Context:
16
16
 
17
17
// A Client is an HTTP client. Its zero value (DefaultClient) is a usable client
18
18
// that uses DefaultTransport.
 
19
//
 
20
// The Client's Transport typically has internal state (cached
 
21
// TCP connections), so Clients should be reused instead of created as
 
22
// needed. Clients are safe for concurrent use by multiple goroutines.
 
23
//
19
24
// Client is not yet very configurable.
20
25
type Client struct {
21
26
        Transport RoundTripper // if nil, DefaultTransport is used
36
41
 
37
42
// RoundTripper is an interface representing the ability to execute a
38
43
// single HTTP transaction, obtaining the Response for a given Request.
 
44
//
 
45
// A RoundTripper must be safe for concurrent use by multiple
 
46
// goroutines.
39
47
type RoundTripper interface {
40
48
        // RoundTrip executes a single HTTP transaction, returning
41
49
        // the Response for the request req.  RoundTrip should not
173
181
                                // Add the Referer header.
174
182
                                lastReq := via[len(via)-1]
175
183
                                if lastReq.URL.Scheme != "https" {
176
 
                                        req.Referer = lastReq.URL.String()
 
184
                                        req.Header.Set("Referer", lastReq.URL.String())
177
185
                                }
178
186
 
179
187
                                err = redirectChecker(req, via)
190
198
                if shouldRedirect(r.StatusCode) {
191
199
                        r.Body.Close()
192
200
                        if url = r.Header.Get("Location"); url == "" {
193
 
                                err = os.ErrorString(fmt.Sprintf("%d response missing Location header", r.StatusCode))
 
201
                                err = os.NewError(fmt.Sprintf("%d response missing Location header", r.StatusCode))
194
202
                                break
195
203
                        }
196
204
                        base = req.URL
207
215
 
208
216
func defaultCheckRedirect(req *Request, via []*Request) os.Error {
209
217
        if len(via) >= 10 {
210
 
                return os.ErrorString("stopped after 10 redirects")
 
218
                return os.NewError("stopped after 10 redirects")
211
219
        }
212
220
        return nil
213
221
}