summaryrefslogtreecommitdiff
path: root/internal/httpclient/client.go
diff options
context:
space:
mode:
authorLibravatar tobi <31960611+tsmethurst@users.noreply.github.com>2022-05-26 13:38:41 +0200
committerLibravatar GitHub <noreply@github.com>2022-05-26 13:38:41 +0200
commit1cdc163276f3437645c0b2c01602e53fa2292c46 (patch)
tree98d21b38fccfed0caadfa06cd937d505d84175aa /internal/httpclient/client.go
parent[performance] Bump default workers to CPUs * 2 (#608) (diff)
downloadgotosocial-1cdc163276f3437645c0b2c01602e53fa2292c46.tar.xz
[performance] Don't retry/backoff invalid http requests that will never succeed (#609)v0.3.4
* add httpguts (ew) * add ValidateRequest err wrapping logic * don't retry on unrecoverable errors * i am very clever
Diffstat (limited to 'internal/httpclient/client.go')
-rw-r--r--internal/httpclient/client.go8
1 files changed, 8 insertions, 0 deletions
diff --git a/internal/httpclient/client.go b/internal/httpclient/client.go
index 1a1f5e53b..55b98bbb6 100644
--- a/internal/httpclient/client.go
+++ b/internal/httpclient/client.go
@@ -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 {