Skip to content

Commit

Permalink
Embed http.Client as a pointer
Browse files Browse the repository at this point in the history
  • Loading branch information
madhuravi committed Nov 23, 2016
1 parent 98b4147 commit cf1dd60
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 7 deletions.
6 changes: 3 additions & 3 deletions modules/uhttp/client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,12 @@ import (

// Client wraps around a http client
type Client struct {
http.Client
*http.Client
filters []Filter
}

// New creates a new instance of uhttp Client
func New(client http.Client, filters ...Filter) *Client {
func New(client *http.Client, filters ...Filter) *Client {
filters = append(filters, FilterFunc(tracingFilter))
return &Client{Client: client, filters: filters}
}
Expand All @@ -56,7 +56,7 @@ func (c *Client) Do(ctx core.Context, req *http.Request) (resp *http.Response, e
}

func (c *Client) do(ctx core.Context, req *http.Request) (resp *http.Response, err error) {
return ctxhttp.Do(ctx, &c.Client, req)
return ctxhttp.Do(ctx, c.Client, req)
}

// Get is a context-aware, filter-enabled extension of Get() in http.Client
Expand Down
8 changes: 4 additions & 4 deletions modules/uhttp/client/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,11 @@ import (
)

var _defaultHTTPClient = &http.Client{Timeout: 2 * time.Second}
var _defaultUHTTPClient = New(*_defaultHTTPClient)
var _defaultUHTTPClient = New(_defaultHTTPClient)

func TestNew(t *testing.T) {
uhttpClient := New(*_defaultHTTPClient)
assert.Equal(t, *_defaultHTTPClient, uhttpClient.Client)
uhttpClient := New(_defaultHTTPClient)
assert.Equal(t, _defaultHTTPClient, uhttpClient.Client)
assert.Equal(t, 1, len(uhttpClient.filters))
}

Expand All @@ -50,7 +50,7 @@ func TestClientDo(t *testing.T) {
}

func TestClientDoWithoutFilters(t *testing.T) {
uhttpClient := &Client{Client: *_defaultHTTPClient}
uhttpClient := &Client{Client: _defaultHTTPClient}
svr := startServer()
req := createHTTPClientRequest(svr.URL)
resp, err := uhttpClient.Do(createContext(), req)
Expand Down

0 comments on commit cf1dd60

Please sign in to comment.