Commit d3d67299 authored by Brad Fitzpatrick's avatar Brad Fitzpatrick

http: rename interface Transport to RoundTripper

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
parent dbff0ada
...@@ -20,26 +20,28 @@ import ( ...@@ -20,26 +20,28 @@ import (
// that uses DefaultTransport. // that uses DefaultTransport.
// Client is not yet very configurable. // Client is not yet very configurable.
type Client struct { 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. // DefaultClient is the default Client and is used by Get, Head, and Post.
var DefaultClient = &Client{} 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. // single HTTP transaction, obtaining the Response for a given Request.
type Transport interface { type RoundTripper interface {
// Do executes a single HTTP transaction, returning the Response for the // RoundTrip executes a single HTTP transaction, returning
// request req. Do should not attempt to interpret the response. // the Response for the request req. RoundTrip should not
// In particular, Do must return err == nil if it obtained a response, // attempt to interpret the response. In particular,
// regardless of the response's HTTP status code. A non-nil err should // RoundTrip must return err == nil if it obtained a response,
// be reserved for failure to obtain a response. Similarly, Do should // regardless of the response's HTTP status code. A non-nil
// not attempt to handle higher-level protocol details such as redirects, // 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. // authentication, or cookies.
// //
// Transports may modify the request. The request Headers field is // RoundTrip may modify the request. The request Headers field is
// guaranteed to be initalized. // guaranteed to be initialized.
Do(req *Request) (resp *Response, err os.Error) RoundTrip(req *Request) (resp *Response, err os.Error)
} }
// Given a string of the form "host", "host:port", or "[ipv6::address]:port", // 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) { ...@@ -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. // send issues an HTTP request. Caller should close resp.Body when done reading from it.
// func send(req *Request, t RoundTripper) (resp *Response, err os.Error) {
// 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) {
if t == nil { if t == nil {
t = DefaultTransport t = DefaultTransport
if t == nil { if t == nil {
...@@ -130,7 +128,7 @@ func send(req *Request, t Transport) (resp *Response, err os.Error) { ...@@ -130,7 +128,7 @@ func send(req *Request, t Transport) (resp *Response, err os.Error) {
} }
req.Header.Set("Authorization", "Basic "+string(encoded)) 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 // True if the specified HTTP status code is one for which the Get utility should
......
...@@ -55,7 +55,7 @@ type recordingTransport struct { ...@@ -55,7 +55,7 @@ type recordingTransport struct {
req *Request 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 t.req = req
return nil, os.NewError("dummy impl") return nil, os.NewError("dummy impl")
} }
......
...@@ -20,7 +20,7 @@ import ( ...@@ -20,7 +20,7 @@ import (
// each call to Do and uses HTTP proxies as directed by the // each call to Do and uses HTTP proxies as directed by the
// $HTTP_PROXY and $NO_PROXY (or $http_proxy and $no_proxy) // $HTTP_PROXY and $NO_PROXY (or $http_proxy and $no_proxy)
// environment variables. // environment variables.
var DefaultTransport Transport = &transport{} var DefaultTransport RoundTripper = &transport{}
// transport implements Tranport for the default case, using TCP // transport implements Tranport for the default case, using TCP
// connections to either the host or a proxy, serving http or https // connections to either the host or a proxy, serving http or https
...@@ -35,7 +35,7 @@ type transport struct { ...@@ -35,7 +35,7 @@ type transport struct {
hostConn map[string]*ClientConn 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 == nil {
if req.URL, err = ParseURL(req.RawURL); err != nil { if req.URL, err = ParseURL(req.RawURL); err != nil {
return return
......
...@@ -30,9 +30,9 @@ func TestTransportNilURL(t *testing.T) { ...@@ -30,9 +30,9 @@ func TestTransportNilURL(t *testing.T) {
// TODO(bradfitz): test &transport{} and not DefaultTransport // TODO(bradfitz): test &transport{} and not DefaultTransport
// once Transport is exported. // once Transport is exported.
res, err := DefaultTransport.Do(req) res, err := DefaultTransport.RoundTrip(req)
if err != nil { if err != nil {
t.Fatalf("unexpected Do error: %v", err) t.Fatalf("unexpected RoundTrip error: %v", err)
} }
body, err := ioutil.ReadAll(res.Body) body, err := ioutil.ReadAll(res.Body)
if g, e := string(body), "Hi"; g != e { if g, e := string(body), "Hi"; g != e {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment