-
SummaryHi! I have the following problem - I'm writing a server that expects large files in some POST requests. The serves uses an The code looks roughly like this: // ROUTE INITIALIZATION
Router::new()
.route("/*path", post(upload_file))
.layer(from_extractor_with_state::<
AuthExtractor,
AuthState,
>(AuthState::new_from_env()))
...
// UPLOAD FILE FUNCTION
async fn upload_file(
path: Option<Path<String>>,
headers: HeaderMap,
body: String,
) -> Result<Response, Response> {
...
} The problem occurs when a large enough file is uploaded and the request fails authentication. Instead of returning This is probably due to the issue mentioned here #2168 , which itself is a byproduct of this issue: hyperium/hyper#2384 . TL;DR the request is supposed to fail early, body is not consumed, TCP reset is sent, connection is dropped (...ISTIO layer sends 503). My question is - Thanks a lot! 🙏 axum version0.7.7 |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 3 replies
-
You can use an auth layer instead of just an extractor. Then you can drain the body only if you intend to return 401 and leave it in place for inner services and the handler itself. |
Beta Was this translation helpful? Give feedback.
tbh I'm not sure why I worked at the time with an Extractor to begin with.
using from_fn_with_state did the trick.
For anyone who might reach this post in the future - I ended up with something like this: