-
-
Notifications
You must be signed in to change notification settings - Fork 15
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
lost context when use @fastify/multipart #153
Comments
The comment from source code already explain why it happen. fastify-request-context/index.js Lines 32 to 41 in e5a7220
It would be better to point it out in the readme. |
@climba03003 Shouldn't the commented block help restore the correct context in that case? It was added to fix the context being lost when using body-parser, I wonder if some additional tweak is needed there to correctly handle multipart parsing hook as well. |
Yes, it also explain why the parser will mess up the context because |
@climba03003 @kibertoad |
I'll write a couple of tests, but I think that it should work correctly if you register request-context plugin after the multipart one, so that it gets a chance to rebind the context correctly |
Yes, I register In my situaction, I want:
Now, Call To avoid performance issue, I need to set property to |
I think we should solve this in our multipart module by adding a AsyncResource at the right moment. |
Thanks for reporting! Would you like to send a Pull Request to address this issue? Remember to add unit tests. |
@climba03003 @mcollina Now that #173 has been merged, does that mean this issue can be resolved? Or is there still work left to fix compatibility with @fastify/multipart? Asking so I can at least raise a quick PR to add this gotcha to the readme |
Prerequisites
Fastify version
4.15.0
Plugin version
4.2.0
Node.js version
18.14.0
Operating system
macOS
Operating system version (i.e. 20.04, 11.3, 10)
11.3
Description
when register
multipart
aftercontext
, the router frequently lost context infoSteps to Reproduce
use
postman
to send any file tohttp://127.0.0.1/
,console.log(req.requestContext.get('user'))
sometimes areundefined
Expected Behavior
No response
The text was updated successfully, but these errors were encountered: