go-retryablehttp | Retryable HTTP client in Go | HTTP library
kandi X-RAY | go-retryablehttp Summary
kandi X-RAY | go-retryablehttp Summary
[Go Documentation] [travis]: [godocs]: The retryablehttp package provides a familiar HTTP client interface with automatic retries and exponential backoff. It is a thin wrapper over the standard net/http client library and exposes nearly the same public API. This makes retryablehttp very easy to drop into existing programs. retryablehttp performs automatic retries under certain conditions. Mainly, if an error is returned by the client (connection errors, etc.), or if a 500-range response code is received (except 501), then a retry is invoked after a wait period. Otherwise, the response is returned and left to the caller to interpret. The main difference from net/http is that requests which take a request body (POST/PUT et. al) can have the body provided in a number of ways (some more or less efficient) that allow "rewinding" the request body if the initial request fails so that the full request can be attempted again. See the [godoc] for more details. Version 0.6.0 and before are compatible with Go prior to 1.12. From 0.6.1 onward, Go 1.12+ is required. From 0.6.7 onward, Go 1.13+ is required.
Support
Quality
Security
License
Reuse
Top functions reviewed by kandi - BETA
Currently covering the most popular Java, JavaScript and Python libraries. See a Sample of go-retryablehttp
go-retryablehttp Key Features
go-retryablehttp Examples and Code Snippets
Community Discussions
Trending Discussions on go-retryablehttp
QUESTION
Using hashicorp go-retryablehttp
library (https://github.com/hashicorp/go-retryablehttp)
It retries automatically for all 5xx
code:
retryablehttp performs automatic retries under certain conditions. Mainly, if an error is returned by the client (connection errors, etc.), or if a 500-range response code is received (except 501), then a retry is invoked after a wait period. Otherwise, the response is returned and left to the caller to interpret.
Is that possible it retries on Request Timeout
, e.g. on 408
http status code just ootb?
or I should build some custom wrappers?
ANSWER
Answered 2021-Aug-03 at 13:44You can implement your own retry policy and pass it to the Client.CheckRetry field.
Doc ref:
- https://pkg.go.dev/github.com/hashicorp/go-retryablehttp?utm_source=godoc#Client
- https://pkg.go.dev/github.com/hashicorp/go-retryablehttp?utm_source=godoc#DefaultRetryPolicy
Code ref:
- https://github.com/hashicorp/go-retryablehttp/blob/02c1586c8f14be23e7eeb522f1094afbabf45e93/client.go#L401
- https://github.com/hashicorp/go-retryablehttp/blob/02c1586c8f14be23e7eeb522f1094afbabf45e93/client.go#L424
The code might look like something similar to
QUESTION
I would like to understand how to use go-retryablehttp with a Client with a custom Transport, let's say for instance to disable TLS validation, how can this be achieved?
...ANSWER
Answered 2020-Nov-30 at 23:31You can access the underlying http client as seen in this issue. Here is a small example of ignoring an self signed cert error at 127.0.0.1:8030
QUESTION
I want to implement a custom http.Transport
for standard http.Client
, which will retry automatically if the client got timeout.
P.S. for some reason, the custom http.Transport
is a must-have. I've already checked hashicorp/go-retryablehttp, however it won't let me use my own http.Transport
.
Here's my attempts, the custom component:
...ANSWER
Answered 2020-Jul-15 at 06:52There is no need to customize the http.Client or such things. You can simply wrap your fetch operation into a retry -- there are plenty of modules available that do the trick:
Community Discussions, Code Snippets contain sources that include Stack Exchange Network
Vulnerabilities
No vulnerabilities reported
Install go-retryablehttp
Support
Reuse Trending Solutions
Find, review, and download reusable Libraries, Code Snippets, Cloud APIs from over 650 million Knowledge Items
Find more librariesStay Updated
Subscribe to our newsletter for trending solutions and developer bootcamps
Share this Page