Skip to content

How to defer generating a Response until after handlers have run #2953

Answered by j-n-f
j-n-f asked this question in Q&A
Discussion options

You must be logged in to vote

I think I've rubber-ducked this one.

  1. handlers can return Response<AppResponse>
  2. a middleware will collect headers from the Request, call Next::run(), then take that Response and copy the request header data into the response as an extension
  3. impl IntoResponse for Response<AppResponse>; between values in extension data and the custom struct I should be able to do what I want and produce a Response<Body>.

✅ still works for values other than Response<AppResponse>
✅ don't need to create dummy responses

Replies: 4 comments

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Answer selected by j-n-f
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
1 participant