http retry round tripper library

334 views
Skip to first unread message

mmat...@gmail.com

unread,
Jun 26, 2018, 1:12:05 PM6/26/18
to golang-nuts
Can someone recommend a http retry round tripper library? 
I searched multiple projects none is doing what I want.
The closest is https://github.com/hashicorp/go-retryablehttp but it's a full client, I'm tempted to port it to http.RoundTripper.

Thanks

Peter Mogensen

unread,
Jun 27, 2018, 1:17:53 AM6/27/18
to golan...@googlegroups.com


On 06/26/2018 05:39 PM, mmat...@gmail.com wrote:
> Can someone recommend a http retry round tripper library? 
> I searched multiple projects none is doing what I want.
>

Does this meet your needs?

https://github.com/One-com/gone/tree/master/http/vtransport

The docs could be better, I admit.

/Peter

golang...@gmail.com

unread,
Jun 27, 2018, 11:48:34 AM6/27/18
to golang-nuts
it's shouldn't be difficult to adapt it to an http.RoundTripper yourself

potentially there are some details/considerations missing in this implementation tho?

type Adapter struct {
retryable *retryablehttp.Client
}


func (a Adapter) RoundTrip(r *http.Request) (*http.Response, error) {
var body io.ReadSeeker
if r.Body != nil {
defer r.Body.Close()
b, err := ioutil.ReadAll(r.Body)
if err != nil {
return nil, err
}
body = bytes.NewReader(b)
}

req, err := retryablehttp.NewRequest(r.Method, r.URL.String(), body)
if err != nil {
return nil, err
}
req.Header = r.Header

return a.retryable.Do(req)
}

golang...@gmail.com

unread,
Jun 27, 2018, 12:39:12 PM6/27/18
to golang-nuts
you could also copy the body w/ `io.Copy`
Reply all
Reply to author
Forward
0 new messages