diff options
| author | Niall Sheridan <nsheridan@gmail.com> | 2018-08-23 22:51:21 +0100 | 
|---|---|---|
| committer | Niall Sheridan <nsheridan@gmail.com> | 2018-08-24 13:45:03 +0100 | 
| commit | f8e3dea19012ccf05965d10255789eec33c2ebcf (patch) | |
| tree | 8522ceada8bc7270648f29615b89550db910cb6c /vendor/github.com/hashicorp/go-retryablehttp | |
| parent | 91f9bc722152146466523861162b85195f99875b (diff) | |
Update deps
Diffstat (limited to 'vendor/github.com/hashicorp/go-retryablehttp')
| -rw-r--r-- | vendor/github.com/hashicorp/go-retryablehttp/client.go | 19 | 
1 files changed, 16 insertions, 3 deletions
| diff --git a/vendor/github.com/hashicorp/go-retryablehttp/client.go b/vendor/github.com/hashicorp/go-retryablehttp/client.go index c016939..21f45e5 100644 --- a/vendor/github.com/hashicorp/go-retryablehttp/client.go +++ b/vendor/github.com/hashicorp/go-retryablehttp/client.go @@ -23,6 +23,7 @@ package retryablehttp  import (  	"bytes" +	"context"  	"fmt"  	"io"  	"io/ioutil" @@ -73,6 +74,13 @@ type Request struct {  	*http.Request  } +// WithContext returns wrapped Request with a shallow copy of underlying *http.Request +// with its context changed to ctx. The provided ctx must be non-nil. +func (r *Request) WithContext(ctx context.Context) *Request { +	r.Request = r.Request.WithContext(ctx) +	return r +} +  // NewRequest creates a new wrapped request.  func NewRequest(method, url string, rawBody interface{}) (*Request, error) {  	var err error @@ -196,7 +204,7 @@ type ResponseLogHook func(*log.Logger, *http.Response)  // Client will close any response body when retrying, but if the retry is  // aborted it is up to the CheckResponse callback to properly close any  // response body before returning. -type CheckRetry func(resp *http.Response, err error) (bool, error) +type CheckRetry func(ctx context.Context, resp *http.Response, err error) (bool, error)  // Backoff specifies a policy for how long to wait between retries.  // It is called after a failing request to determine the amount of time @@ -253,7 +261,12 @@ func NewClient() *Client {  // DefaultRetryPolicy provides a default callback for Client.CheckRetry, which  // will retry on connection errors and server errors. -func DefaultRetryPolicy(resp *http.Response, err error) (bool, error) { +func DefaultRetryPolicy(ctx context.Context, resp *http.Response, err error) (bool, error) { +	// do not retry on context.Canceled or context.DeadlineExceeded +	if ctx.Err() != nil { +		return false, ctx.Err() +	} +  	if err != nil {  		return true, err  	} @@ -361,7 +374,7 @@ func (c *Client) Do(req *Request) (*http.Response, error) {  		}  		// Check if we should continue with retries. -		checkOK, checkErr := c.CheckRetry(resp, err) +		checkOK, checkErr := c.CheckRetry(req.Request.Context(), resp, err)  		if err != nil {  			if c.Logger != nil { | 
