LEFT | RIGHT |
1 // Copyright 2009 The Go Authors. All rights reserved. | 1 // Copyright 2009 The Go Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style | 2 // Use of this source code is governed by a BSD-style |
3 // license that can be found in the LICENSE file. | 3 // license that can be found in the LICENSE file. |
4 | 4 |
5 // Primitive HTTP client. See RFC 2616. | 5 // Primitive HTTP client. See RFC 2616. |
6 | 6 |
7 package http | 7 package http |
8 | 8 |
9 import ( | 9 import ( |
10 "bytes" | 10 "bytes" |
11 "encoding/base64" | 11 "encoding/base64" |
12 "fmt" | 12 "fmt" |
13 "io" | 13 "io" |
14 "os" | 14 "os" |
15 "strconv" | 15 "strconv" |
16 "strings" | 16 "strings" |
17 ) | 17 ) |
18 | 18 |
19 // A Client is an HTTP client. Its zero value (DefaultClient) is a usable client | 19 // A Client is an HTTP client. Its zero value (DefaultClient) is a usable client |
20 // that uses DefaultTransport. | 20 // that uses DefaultTransport. |
21 // Client is not yet very configurable. | 21 // Client is not yet very configurable. |
22 type Client struct { | 22 type Client struct { |
23 Transport ClientTransport // if nil, DefaultTransport is used | 23 Transport ClientTransport // if nil, DefaultTransport is used |
24 } | 24 } |
25 | 25 |
26 // DefaultClient is the default Client and is used by Get, Head, and Post. | 26 // DefaultClient is the default Client and is used by Get, Head, and Post. |
27 var DefaultClient = &Client{} | 27 var DefaultClient = &Client{} |
28 | |
29 // NewClient returns a new Client which you can then initialize as needed. | |
30 func NewClient() *Client { | |
31 return &Client{} | |
32 } | |
33 | 28 |
34 // ClientTransport is an interface representing the ability to execute a | 29 // ClientTransport is an interface representing the ability to execute a |
35 // single HTTP transaction, obtaining the Response for a given Request. | 30 // single HTTP transaction, obtaining the Response for a given Request. |
36 type ClientTransport interface { | 31 type ClientTransport interface { |
37 // Do executes a single HTTP transaction, returning the Response for the | 32 // Do executes a single HTTP transaction, returning the Response for the |
38 // request req. Do should not attempt to interpret the response. | 33 // request req. Do should not attempt to interpret the response. |
39 // In particular, Do must return err == nil if it obtained a response, | 34 // In particular, Do must return err == nil if it obtained a response, |
40 // regardless of the response's HTTP status code. A non-nil err should | 35 // regardless of the response's HTTP status code. A non-nil err should |
41 // be reserved for failure to obtain a response. Similarly, Do should | 36 // be reserved for failure to obtain a response. Similarly, Do should |
42 // not attempt to handle higher-level protocol details such as redirects
, | 37 // not attempt to handle higher-level protocol details such as redirects
, |
(...skipping 262 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
305 return | 300 return |
306 } | 301 } |
307 return send(&req, c.Transport) | 302 return send(&req, c.Transport) |
308 } | 303 } |
309 | 304 |
310 type nopCloser struct { | 305 type nopCloser struct { |
311 io.Reader | 306 io.Reader |
312 } | 307 } |
313 | 308 |
314 func (nopCloser) Close() os.Error { return nil } | 309 func (nopCloser) Close() os.Error { return nil } |
LEFT | RIGHT |