[feature/performance] Wrap incoming HTTP requests in timeout handler (#2353)

* deinterface router, start messing about with deadlines

* weeeee

* thanks linter (thinter)

* write Connection: close when timing out requests

* update wording

* don't replace req

* don't bother with fancy Cause functions (I'll use them one day...)
This commit is contained in:
tobi 2023-11-13 19:48:51 +01:00 committed by GitHub
commit 8d0c017cf2
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
14 changed files with 305 additions and 175 deletions

View file

@ -198,3 +198,14 @@ func NewErrorClientClosedRequest(original error) WithCode {
code: StatusClientClosedRequest,
}
}
// NewErrorRequestTimeout returns an ErrorWithCode 408 with the given original error.
// This error type should only be used when the server has decided to hang up a client
// request after x amount of time, to avoid keeping extremely slow client requests open.
func NewErrorRequestTimeout(original error) WithCode {
return withCode{
original: original,
safe: errors.New(http.StatusText(http.StatusRequestTimeout)),
code: http.StatusRequestTimeout,
}
}