-
Notifications
You must be signed in to change notification settings - Fork 203
Description
Feature Request
Motivation
I'd like to be able to return a 504 if the timeout given to the TimeoutLayer
is exceeded. This is because a 408, which is currently returned, is meant to
communicate:
that the server did not receive a complete request message within the time
that it was prepared to wait.
I don't know if in general we can tell if the issue is the client sending the
request or the server processing the request but in the case of the latter
(especially because this service is proxying to another) I'd like to return
a 504 Gateway Timeout instead (which is still not a guarantee - the issue
could have been the upstream or any post-processing of the upstream's
response but that's rare in this case). Servers like axum
and actix-web
provide other mechanisms for timeouts when receiving things like request
headers12 so maybe something about receiving the request should be handled
at the server level or by something like BodyTimeout
?
Proposal
Changing the response status from 408 all the time to 504 all the time
would equally be incorrect sometimes and would be a breaking change.
Luckily we already have a new()
constructor for TimeoutLayer
so I
imagine that could stay the same and default to 408 and then we could
have a new_with_response
constructor that accepts an http::Response<B>
or similar that can be returned instead.
Alternatives
The most obvious alternative I can see follows from this comment
which is to use tower
instead of tower-http
and explicitly catch the
error and perform custom logic on it. This isn't too much code but I
wonder if the alternate constructor is valuable because I'm not sure
how frequent 408 will be the desired response code (though HTTP
semantics are fuzzy enough that maybe it's not worth it!).