Skip to content

Commit

Permalink
#18 - returns response too when redirect error
Browse files Browse the repository at this point in the history
  • Loading branch information
jeevatkm committed Dec 28, 2015
1 parent 221d129 commit 298f2a1
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 7 deletions.
9 changes: 5 additions & 4 deletions client.go
Original file line number Diff line number Diff line change
Expand Up @@ -571,21 +571,22 @@ func (c *Client) execute(req *Request) (*Response, error) {
req.Time = time.Now()
c.httpClient.Transport = c.transport
resp, err := c.httpClient.Do(req.RawRequest)
if err != nil {
return nil, err
}

response := &Response{
Request: req,
RawResponse: resp,
receivedAt: time.Now(),
}

if err != nil {
return response, err
}

if !req.isSaveResponse {
defer resp.Body.Close()
response.body, err = ioutil.ReadAll(resp.Body)
if err != nil {
return nil, err
return response, err
}

response.size = int64(len(response.body))
Expand Down
6 changes: 3 additions & 3 deletions resty_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -857,7 +857,7 @@ func TestClientProxy(t *testing.T) {
c.SetProxy("http://sampleproxy:8888")

resp, err := c.R().Get(ts.URL)
assertEqual(t, true, resp == nil)
assertEqual(t, true, resp != nil)
assertEqual(t, true, err != nil)
}

Expand All @@ -871,7 +871,7 @@ func TestPerRequestProxy(t *testing.T) {
resp, err := c.R().
SetProxy("http://sampleproxy:8888").
Get(ts.URL)
assertEqual(t, true, resp == nil)
assertEqual(t, true, resp != nil)
assertEqual(t, true, err != nil)
}

Expand All @@ -886,7 +886,7 @@ func TestClientProxyOverride(t *testing.T) {
resp, err := c.R().
SetProxy("http://requestproxy:8888").
Get(ts.URL)
assertEqual(t, true, resp == nil)
assertEqual(t, true, resp != nil)
assertEqual(t, true, err != nil)
}

Expand Down

0 comments on commit 298f2a1

Please sign in to comment.