Retry checking refactored using util function.
This commit is contained in:
parent
46c4db6b1a
commit
be4d13c0ef
@ -105,15 +105,13 @@ func (c *Client) DoRequest(req *Request) (resp *Response, err error) {
|
||||
}
|
||||
|
||||
// Retry on http status codes
|
||||
for _, statusCode := range c.opt.RetryHTTPCodes {
|
||||
if resp.StatusCode == statusCode {
|
||||
if internal.ContainsInt(c.opt.RetryHTTPCodes, resp.StatusCode) {
|
||||
if req.retryCounter < c.opt.RetryTimes {
|
||||
req.retryCounter++
|
||||
internal.Logger.Println("Retrying:", req.URL.String(), resp.StatusCode)
|
||||
return c.DoRequest(req)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return resp, err
|
||||
}
|
||||
|
@ -16,8 +16,18 @@ func DefaultRune(val rune, valDefault rune) rune {
|
||||
return valDefault
|
||||
}
|
||||
|
||||
// Contains checks whether []string Contains string
|
||||
func Contains(s []string, e string) bool {
|
||||
// ContainsString checks whether []string ContainsString string
|
||||
func ContainsString(s []string, e string) bool {
|
||||
for _, a := range s {
|
||||
if a == e {
|
||||
return true
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
// ContainsInt checks whether []int contains int
|
||||
func ContainsInt(s []int, e int) bool {
|
||||
for _, a := range s {
|
||||
if a == e {
|
||||
return true
|
||||
|
@ -13,7 +13,7 @@ type AllowedDomains struct {
|
||||
}
|
||||
|
||||
func (a *AllowedDomains) ProcessRequest(r *client.Request) {
|
||||
if len(a.AllowedDomains) != 0 && !internal.Contains(a.AllowedDomains, r.Host) {
|
||||
if len(a.AllowedDomains) != 0 && !internal.ContainsString(a.AllowedDomains, r.Host) {
|
||||
if _, logged := a.logOnlyOnce.LoadOrStore(r.Host, struct{}{}); !logged {
|
||||
internal.Logger.Printf("Domain not allowed: %s\n", r.Host)
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user