hashicorp / go-retryablehttp

Retryable HTTP client in Go
Mozilla Public License 2.0
1.99k stars 251 forks source link

[Question] Need http "method" in custom CheckRetry function #114

Closed padamstx closed 4 years ago

padamstx commented 4 years ago

Hi, I've started to incorporate the use of retryablehttp into an existing Go library. One thing that I'll likely need to do is implement a custom CheckRetry function. In my case, I will need to use the http.Request's "Method" field, in conjunction with the response status code and "error", to determine if a retry is needed/wanted. For example, I want to avoid doing retries for a POST or PUT unless the error was some sort of client connection error (e.g. If a POST/PUT encounters a timeout, I don't want to retry because there's no way of knowing if the server actually did complete the request after the client timeout occurred; but if a client error occurred due to a temporary network hiccup, then a retry can be attempted).

Unfortunately, the CheckRetry function signature doesn't seem to provide the http.Request or any of the other request-specific info. Is there any advice you could provide for how to get access to the http.Request's "Method" field from within a custom CheckRetry function?

Thanks in advance!

padamstx commented 4 years ago
Please disregard... I just discovered that the http.Response contains the "Request" field :)