-
-
Notifications
You must be signed in to change notification settings - Fork 24
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
Headers are null
when using .inject
#47
Headers are null
when using .inject
#47
Comments
Would you like to send a Pull Request to address this issue? Remember to add unit tests. |
Happy to, but I don't know what the fix is. Any pointers? I can send a PR with what I have locally which I don't think is the correct fix, but that's in |
The fix should be here. |
Right, makes sense. I don't think I'll be able to send a PR though as I don't know what the fix is 😅 |
My understanding is that light-my-request cannot work with Express as the latter does a lot of prototype chain manipulation that light-my-request is not really liking. I think the fix should/would be in light-my-request. |
Yeah, that seems reasonable. I can send the PR I was talking about above, and we can figure out if it's an ok way to go? |
let's see! |
Opened up fastify/light-my-request#154 |
This has regressed as of fastify/light-my-request#221 apply this diff to get a failure (same as OP, but that doesn't apply cleanly anymore): diff --git i/test/application.test.js w/test/application.test.js
index efc0e4c..a8a44c3 100644
--- i/test/application.test.js
+++ w/test/application.test.js
@@ -145,7 +145,7 @@ test('Should expose the express app on the fastify instance', t => {
})
test('Should flush headers if express handles request', t => {
- t.plan(3)
+ t.plan(2)
const fastify = Fastify()
t.teardown(fastify.close)
@@ -166,14 +166,11 @@ test('Should flush headers if express handles request', t => {
.register(expressPlugin)
.after(() => { fastify.use(router) })
- fastify.listen({ port: 0 }, (err, address) => {
+ fastify.inject({
+ method: 'GET',
+ url: '/'
+ }, (err, res) => {
t.error(err)
- sget({
- method: 'GET',
- url: address
- }, (err, res) => {
- t.error(err)
- t.equal(res.headers.foo, 'bar')
- })
+ t.equal(res.headers.foo, 'bar')
})
}) |
I found the issue: the writehead method is not called because of this line in fastify:
I think the best solution would be to that light-my-request support both the cases instead that this module care about the fastify internals |
Ok, after a lot of debugging, I found that the If you log
The issue comes from here: This code is executed after three express
This prototype switching simply does not execute the So, now I think that we should find how to configure/fix this project instead or, restoring the previous code in What I tried but failed to do on this repo:
|
@mcollina should we reintroduce the header code removed from |
I have no time to dig into the problem atm (I'll be very busy until mid-october), I'm ok with a full revert or whatever fix you think it's appropriate. |
Cool, I'll send a PR 👍 I don't think we need to revert, just re-add the somewhat hacky header code |
Prerequisites
Fastify version
3.20.2
Plugin version
0.3.3
Node.js version
14.17.5
Operating system
macOS
Operating system version (i.e. 20.04, 11.3, 10)
11.5.1
Description
When using
fastify.inject
and this plugin,res.headers
is alwaysnull
. The headers are inres.raw.res.getHeaders()
FWIW.Debugging, https://github.com/fastify/light-my-request/blob/014c1c8016f8605b5ca4c7906f527d5ab0b17267/lib/response.js#L66-L81 is never called
Steps to Reproduce
In this repo, change
fastify.listen
tofastify.inject
Expected Behavior
headers
should be populatedThe text was updated successfully, but these errors were encountered: