-
-
Notifications
You must be signed in to change notification settings - Fork 132
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
feat(ClientRequest): implement "flushHeaders()" #442
Conversation
kettanaito
commented
Sep 22, 2023
- Fixes Support http.request flushHeaders #439
* | ||
* @see https://github.com/nodejs/node/blob/c2cd74453e7d2794ad81cab63e68371e08bad04f/lib/_http_outgoing.js#L1161 | ||
*/ | ||
this.end('') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think this is correct (see the comment above).
We don't distinguish between writing headers and body in the interceptor, we only tap into the write()
and end()
methods.
I've moved forward with the implementation for this. Right now, the main challenge is to distinguish between these two scenarios:
Since the @mikicho, maybe you've got some thoughts on this? |
This is interesting. I didn't know about the From what I see, Nock runs the interceptors logic, and don't wait for further After reading your insights and Node code. I think Nock implemented it incorrectly, So, I think we need to do nothing on WDYT? |
That's the same thing! Node.js buffers the request body entirely before sending it to the server with
|
const req = http.request('http://httpstat.us/200')
const emitSpy = sinon.spy(req, 'emit')
req.setHeader('my-header', 'tes')
req.flushHeaders()
req.on('response', res => {
const emitSpyRes = sinon.spy(res, 'emit')
res.on('data', () => {})
res.on('end', () => {
console.log(emitSpy.getCalls().map(e => e.firstArg))
console.log(emitSpyRes.getCalls().map(e => e.firstArg))
done()
})
req.end()
}) This prints:
If I remove the
So it seems like we want to run the interceptor (request) and return mockedResponse if it exists. |
Closing in favor of #515. Relying on the Socket will automatically support |
Released: v0.32.0 🎉This has been released in v0.32.0! Make sure to always update to the latest version ( Predictable release automation by @ossjs/release. |