Skip to content

How can I use async in actix_web middleware and return a custom HTTP status? #3428

Answered by robjtede
OlalalalaO asked this question in Q&A
Discussion options

You must be logged in to vote

For your case, you'd need to leverage EitherBody.

type Response = ServiceResponse<EitherBody<B, BoxBody>>

However, the easiest way to create async middleware these days is to use middleware::from_fn from the lab (soon to graduate to the main lib). I'd recommend using this instead.

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by robjtede
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants