]> Cypherpunks repositories - gostls13.git/commitdiff
http: rename interface Transport to RoundTripper
authorBrad Fitzpatrick <bradfitz@golang.org>
Fri, 11 Mar 2011 19:32:33 +0000 (11:32 -0800)
committerBrad Fitzpatrick <bradfitz@golang.org>
Fri, 11 Mar 2011 19:32:33 +0000 (11:32 -0800)
Transport.Do -> RoundTripper.RoundTrip

This makes way for a subsequent CL to export the
currently private RoundTripper implementation
as struct Transport.

R=rsc, r
CC=golang-dev
https://golang.org/cl/4286043

src/pkg/http/client.go
src/pkg/http/client_test.go
src/pkg/http/transport.go
src/pkg/http/transport_test.go

index c24eea58191832ad09d89f98992ddfe0ab42ea0c..c4f7e947d8f3393f7de5727f822b15ae56c51426 100644 (file)
@@ -20,26 +20,28 @@ import (
 // that uses DefaultTransport.
 // Client is not yet very configurable.
 type Client struct {
-       Transport Transport // if nil, DefaultTransport is used
+       Transport RoundTripper // if nil, DefaultTransport is used
 }
 
 // DefaultClient is the default Client and is used by Get, Head, and Post.
 var DefaultClient = &Client{}
 
-// Transport is an interface representing the ability to execute a
+// RoundTripper is an interface representing the ability to execute a
 // single HTTP transaction, obtaining the Response for a given Request.
-type Transport interface {
-       // Do executes a single HTTP transaction, returning the Response for the
-       // request req.  Do should not attempt to interpret the response.
-       // In particular, Do must return err == nil if it obtained a response,
-       // regardless of the response's HTTP status code.  A non-nil err should
-       // be reserved for failure to obtain a response.  Similarly, Do should
-       // not attempt to handle higher-level protocol details such as redirects,
+type RoundTripper interface {
+       // RoundTrip executes a single HTTP transaction, returning
+       // the Response for the request req.  RoundTrip should not
+       // attempt to interpret the response.  In particular,
+       // RoundTrip must return err == nil if it obtained a response,
+       // regardless of the response's HTTP status code.  A non-nil
+       // err should be reserved for failure to obtain a response.
+       // Similarly, RoundTrip should not attempt to handle
+       // higher-level protocol details such as redirects,
        // authentication, or cookies.
        //
-       // Transports may modify the request. The request Headers field is
-       // guaranteed to be initalized.
-       Do(req *Request) (resp *Response, err os.Error)
+       // RoundTrip may modify the request. The request Headers field is
+       // guaranteed to be initialized.
+       RoundTrip(req *Request) (resp *Response, err os.Error)
 }
 
 // Given a string of the form "host", "host:port", or "[ipv6::address]:port",
@@ -100,11 +102,7 @@ func (c *Client) Do(req *Request) (resp *Response, err os.Error) {
 
 
 // send issues an HTTP request.  Caller should close resp.Body when done reading from it.
-//
-// TODO: support persistent connections (multiple requests on a single connection).
-// send() method is nonpublic because, when we refactor the code for persistent
-// connections, it may no longer make sense to have a method with this signature.
-func send(req *Request, t Transport) (resp *Response, err os.Error) {
+func send(req *Request, t RoundTripper) (resp *Response, err os.Error) {
        if t == nil {
                t = DefaultTransport
                if t == nil {
@@ -130,7 +128,7 @@ func send(req *Request, t Transport) (resp *Response, err os.Error) {
                }
                req.Header.Set("Authorization", "Basic "+string(encoded))
        }
-       return t.Do(req)
+       return t.RoundTrip(req)
 }
 
 // True if the specified HTTP status code is one for which the Get utility should
index 3d71707881a3cb649cecfba6429d7936aedf3f00..3a6f834253b3fef59b693a8a176df63ddb939ede 100644 (file)
@@ -55,7 +55,7 @@ type recordingTransport struct {
        req *Request
 }
 
-func (t *recordingTransport) Do(req *Request) (resp *Response, err os.Error) {
+func (t *recordingTransport) RoundTrip(req *Request) (resp *Response, err os.Error) {
        t.req = req
        return nil, os.NewError("dummy impl")
 }
index 5ab8080198a189a4b0135c8cc7c1af1fd558ab86..cea1a3b2401890155980ac24edca79602e103e1f 100644 (file)
@@ -20,7 +20,7 @@ import (
 // each call to Do and uses HTTP proxies as directed by the
 // $HTTP_PROXY and $NO_PROXY (or $http_proxy and $no_proxy)
 // environment variables.
-var DefaultTransport Transport = &transport{}
+var DefaultTransport RoundTripper = &transport{}
 
 // transport implements Tranport for the default case, using TCP
 // connections to either the host or a proxy, serving http or https
@@ -35,7 +35,7 @@ type transport struct {
        hostConn map[string]*ClientConn
 }
 
-func (ct *transport) Do(req *Request) (resp *Response, err os.Error) {
+func (ct *transport) RoundTrip(req *Request) (resp *Response, err os.Error) {
        if req.URL == nil {
                if req.URL, err = ParseURL(req.RawURL); err != nil {
                        return
index bb9a15f93459fadde8686abcf160d86a1ad23781..2bdca7b99b760654744a22dd322c866de64126c6 100644 (file)
@@ -30,9 +30,9 @@ func TestTransportNilURL(t *testing.T) {
 
        // TODO(bradfitz): test &transport{} and not DefaultTransport
        // once Transport is exported.
-       res, err := DefaultTransport.Do(req)
+       res, err := DefaultTransport.RoundTrip(req)
        if err != nil {
-               t.Fatalf("unexpected Do error: %v", err)
+               t.Fatalf("unexpected RoundTrip error: %v", err)
        }
        body, err := ioutil.ReadAll(res.Body)
        if g, e := string(body), "Hi"; g != e {