mirror of
https://github.com/superseriousbusiness/gotosocial.git
synced 2024-11-22 03:36:39 +00:00
[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.
This commit is contained in:
parent
51c156cca1
commit
70398891b8
|
@ -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 {
|
||||
|
|
Loading…
Reference in a new issue