Skip to content

Commit

Permalink
fix issue rackspace#621 endless recursion
Browse files Browse the repository at this point in the history
  • Loading branch information
Armstrong Li committed Dec 21, 2016
1 parent e00690e commit 15963ce
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions provider_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,12 @@ var applicationJSON = "application/json"
// Request performs an HTTP request using the ProviderClient's current HTTPClient. An authentication
// header will automatically be provided.
func (client *ProviderClient) Request(method, url string, options RequestOpts) (*http.Response, error) {
return client.request(method, url, options, false)
}

// Request performs an HTTP request using the ProviderClient's current HTTPClient. An authentication
// header will automatically be provided.
func (client *ProviderClient) request(method, url string, options RequestOpts, recursionFlag bool) (*http.Response, error) {
var body io.ReadSeeker
var contentType *string

Expand Down Expand Up @@ -187,14 +193,17 @@ func (client *ProviderClient) Request(method, url string, options RequestOpts) (

// Set connection parameter to close the connection immediately when we've got the response
req.Close = true

// Issue the request.
resp, err := client.HTTPClient.Do(req)
if err != nil {
return nil, err
}

if resp.StatusCode == http.StatusUnauthorized {
if recursionFlag {
return nil, fmt.Errorf("Successfully re-authenticated, but got error executing request: %s", err)
}
if client.ReauthFunc != nil {
err = client.ReauthFunc()
if err != nil {
Expand All @@ -204,7 +213,7 @@ func (client *ProviderClient) Request(method, url string, options RequestOpts) (
options.RawBody.Seek(0, 0)
}
resp.Body.Close()
resp, err = client.Request(method, url, options)
resp, err = client.request(method, url, options, true)
if err != nil {
return nil, fmt.Errorf("Successfully re-authenticated, but got error executing request: %s", err)
}
Expand Down

0 comments on commit 15963ce

Please sign in to comment.