summaryrefslogtreecommitdiff
path: root/internal/httpclient/client.go
diff options
context:
space:
mode:
authorLibravatar Daenney <daenney@users.noreply.github.com>2023-02-19 12:01:15 +0100
committerLibravatar GitHub <noreply@github.com>2023-02-19 11:01:15 +0000
commit70398891b838ae29e5f8e2ce76301a43995c0a5d (patch)
tree21a46fecd2cec74054d48658cdbe91e108ee950e /internal/httpclient/client.go
parentpull in latest go-kv, go-cache (#1530) (diff)
downloadgotosocial-70398891b838ae29e5f8e2ce76301a43995c0a5d.tar.xz
[chore] Move request validation earlier in client (#1531)
This moves checking if the request is valid as early as possible in the chain. This should ensure that for an invalid request we never bother acquiring the wait queue and taking up a spot in it.
Diffstat (limited to 'internal/httpclient/client.go')
-rw-r--r--internal/httpclient/client.go10
1 files changed, 5 insertions, 5 deletions
diff --git a/internal/httpclient/client.go b/internal/httpclient/client.go
index 45f0c3447..b011b7b33 100644
--- a/internal/httpclient/client.go
+++ b/internal/httpclient/client.go
@@ -153,6 +153,11 @@ func New(cfg Config) *Client {
// as the standard http.Client{}.Do() implementation except that response body will
// be wrapped by an io.LimitReader() to limit response body sizes.
func (c *Client) Do(req *http.Request) (*http.Response, error) {
+ // Ensure this is a valid request
+ if err := ValidateRequest(req); err != nil {
+ return nil, err
+ }
+
// Get host's wait queue
wait := c.wait(req.Host)
@@ -198,11 +203,6 @@ func (c *Client) Do(req *http.Request) (*http.Response, error) {
}
}
- // 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 {