diff --git a/client/cluster.go b/client/cluster.go index b57f57c8d..3925d65d1 100644 --- a/client/cluster.go +++ b/client/cluster.go @@ -47,7 +47,7 @@ type httpClusterClient struct { endpoints []*httpClient } -func (c *httpClusterClient) do(ctx context.Context, act httpAction) (int, []byte, error) { +func (c *httpClusterClient) do(ctx context.Context, act httpAction) (*http.Response, []byte, error) { //TODO(bcwaldon): introduce retry logic so all endpoints are attempted return c.endpoints[0].do(ctx, act) } diff --git a/client/http.go b/client/http.go index 5bdf0eebe..7aea99aea 100644 --- a/client/http.go +++ b/client/http.go @@ -43,7 +43,7 @@ type httpAction interface { } type httpActionDo interface { - do(context.Context, httpAction) (int, []byte, error) + do(context.Context, httpAction) (*http.Response, []byte, error) } type roundTripResponse struct { @@ -57,7 +57,7 @@ type httpClient struct { timeout time.Duration } -func (c *httpClient) do(ctx context.Context, act httpAction) (int, []byte, error) { +func (c *httpClient) do(ctx context.Context, act httpAction) (*http.Response, []byte, error) { req := act.httpRequest(c.endpoint) rtchan := make(chan roundTripResponse, 1) @@ -89,9 +89,9 @@ func (c *httpClient) do(ctx context.Context, act httpAction) (int, []byte, error }() if err != nil { - return 0, nil, err + return nil, nil, err } body, err := ioutil.ReadAll(resp.Body) - return resp.StatusCode, body, err + return resp, body, err } diff --git a/client/http_test.go b/client/http_test.go index 3ae6c4d8c..16115958a 100644 --- a/client/http_test.go +++ b/client/http_test.go @@ -78,14 +78,14 @@ func TestHTTPClientDoSuccess(t *testing.T) { Body: ioutil.NopCloser(strings.NewReader("foo")), } - code, body, err := c.do(context.Background(), &fakeAction{}) + resp, body, err := c.do(context.Background(), &fakeAction{}) if err != nil { t.Fatalf("incorrect error value: want=nil got=%v", err) } wantCode := http.StatusTeapot - if wantCode != code { - t.Fatalf("invalid response code: want=%d got=%d", wantCode, code) + if wantCode != resp.StatusCode { + t.Fatalf("invalid response code: want=%d got=%d", wantCode, resp.StatusCode) } wantBody := []byte("foo") diff --git a/client/keys.go b/client/keys.go index 4235c05cc..591d7a4c8 100644 --- a/client/keys.go +++ b/client/keys.go @@ -112,13 +112,13 @@ func (k *httpKeysAPI) Create(key, val string, ttl time.Duration) (*Response, err } ctx, cancel := context.WithTimeout(context.Background(), k.timeout) - code, body, err := k.client.do(ctx, create) + resp, body, err := k.client.do(ctx, create) cancel() if err != nil { return nil, err } - return unmarshalHTTPResponse(code, body) + return unmarshalHTTPResponse(resp.StatusCode, body) } func (k *httpKeysAPI) Get(key string) (*Response, error) { @@ -129,13 +129,13 @@ func (k *httpKeysAPI) Get(key string) (*Response, error) { } ctx, cancel := context.WithTimeout(context.Background(), k.timeout) - code, body, err := k.client.do(ctx, get) + resp, body, err := k.client.do(ctx, get) cancel() if err != nil { return nil, err } - return unmarshalHTTPResponse(code, body) + return unmarshalHTTPResponse(resp.StatusCode, body) } func (k *httpKeysAPI) Watch(key string, idx uint64) Watcher { @@ -169,12 +169,12 @@ type httpWatcher struct { func (hw *httpWatcher) Next() (*Response, error) { //TODO(bcwaldon): This needs to be cancellable by the calling user - code, body, err := hw.client.do(context.Background(), &hw.nextWait) + httpresp, body, err := hw.client.do(context.Background(), &hw.nextWait) if err != nil { return nil, err } - resp, err := unmarshalHTTPResponse(code, body) + resp, err := unmarshalHTTPResponse(httpresp.StatusCode, body) if err != nil { return nil, err } diff --git a/client/members.go b/client/members.go index 780bf28cb..6b2b063fa 100644 --- a/client/members.go +++ b/client/members.go @@ -62,13 +62,13 @@ type httpMembersAPI struct { func (m *httpMembersAPI) List() ([]httptypes.Member, error) { req := &membersAPIActionList{} ctx, cancel := context.WithTimeout(context.Background(), m.timeout) - code, body, err := m.client.do(ctx, req) + resp, body, err := m.client.do(ctx, req) cancel() if err != nil { return nil, err } - if err := assertStatusCode(http.StatusOK, code); err != nil { + if err := assertStatusCode(http.StatusOK, resp.StatusCode); err != nil { return nil, err } @@ -88,13 +88,13 @@ func (m *httpMembersAPI) Add(peerURL string) (*httptypes.Member, error) { req := &membersAPIActionAdd{peerURLs: urls} ctx, cancel := context.WithTimeout(context.Background(), m.timeout) - code, body, err := m.client.do(ctx, req) + resp, body, err := m.client.do(ctx, req) cancel() if err != nil { return nil, err } - if err := assertStatusCode(http.StatusCreated, code); err != nil { + if err := assertStatusCode(http.StatusCreated, resp.StatusCode); err != nil { return nil, err } @@ -109,13 +109,13 @@ func (m *httpMembersAPI) Add(peerURL string) (*httptypes.Member, error) { func (m *httpMembersAPI) Remove(memberID string) error { req := &membersAPIActionRemove{memberID: memberID} ctx, cancel := context.WithTimeout(context.Background(), m.timeout) - code, _, err := m.client.do(ctx, req) + resp, _, err := m.client.do(ctx, req) cancel() if err != nil { return err } - return assertStatusCode(http.StatusNoContent, code) + return assertStatusCode(http.StatusNoContent, resp.StatusCode) } type membersAPIActionList struct{}