From 8d0c017cf205bcf57630c91b53079001deed4d36 Mon Sep 17 00:00:00 2001 From: tobi <31960611+tsmethurst@users.noreply.github.com> Date: Mon, 13 Nov 2023 19:48:51 +0100 Subject: [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...) --- internal/gtserror/withcode.go | 11 +++++++++++ 1 file changed, 11 insertions(+) (limited to 'internal/gtserror') diff --git a/internal/gtserror/withcode.go b/internal/gtserror/withcode.go index 55fe7502a..d17a4e42e 100644 --- a/internal/gtserror/withcode.go +++ b/internal/gtserror/withcode.go @@ -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, + } +} -- cgit v1.3