[performance] Don't retry/backoff invalid http requests that will never succeed (#609)

* add httpguts (ew)

* add ValidateRequest err wrapping logic

* don't retry on unrecoverable errors

* i am very clever
This commit is contained in:
tobi 2022-05-26 13:38:41 +02:00 committed by GitHub
commit 1cdc163276
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
8 changed files with 487 additions and 4 deletions

View file

@ -28,6 +28,9 @@ import (
"time"
)
// ErrInvalidRequest is returned if a given HTTP request is invalid and cannot be performed.
var ErrInvalidRequest = errors.New("invalid http request")
// ErrReservedAddr is returned if a dialed address resolves to an IP within a blocked or reserved net.
var ErrReservedAddr = errors.New("dial within blocked / reserved IP range")
@ -164,6 +167,11 @@ func (c *Client) Do(req *http.Request) (*http.Response, error) {
defer func() { <-c.queue }()
}
// Firstly, ensure this is a valid request
if err := ValidateRequest(req); err != nil {
return nil, err
}
// Perform the HTTP request
rsp, err := c.client.Do(req)
if err != nil {