gojek / heimdall

An enhanced HTTP client for Go
http://gojek.tech
Apache License 2.0
2.63k stars 214 forks source link

fix bug & some optimize #131

Open Panlq opened 2 years ago

Panlq commented 2 years ago
  1. add unit tests TestHTTPClientGetRetriesOnTimeout
  2. fix issue #89/#94: retrier called even with 0 retry count and time sleep will be called even when the retries are exhausted
  3. Cancel the retry sleep if the request context is canceled or the deadline exceeded

some proposal:

  1. an interface or option through which we can customize the retry policy (check error check resp.StatusCode)
  2. some times, we need to know the number of retries and responses when the retrier called. Is any idea about this? I implemented a version using the existing method, but it was not very good get the retry times
type Plugin interface {
    OnRequestStart(*http.Request)
    OnRequestEnd(*http.Request, *http.Response)
    // the response struct contains the request. add a attempt num when the err handler?
    OnError(*http.Response, error, int)   
}