About making an HTTP request the documentation says "The actual header will be sent along with the first data chunk or when closing the connection.". But what if I want to send a request with Expect: 100-continue header? I would like to write only headers and wait for the HTTP status 100 Continue. I can't seem to find a way to do this using the current API. Can you please point me to a working example?
Have you looked into the checkContinue event on the HTTP server instance?
I believe it lets you override the default response
fhalde, that's the server side, which works all fine. But I'm talking about the HTTP client. I would like to do something like:
var req = http.request({
host: 'example.com',
method: 'post',
headers: {
Expect: '100-continue',
},
})
// below is what I expect it to be like
req.flushHeaders()
req.on('continue', () => {
req.en(largeRequestBody)
})
In case it can help, here is the test that we have for this feature: https://github.com/nodejs/node/blob/1b2d3f7ae7f0391908b70b0333a5adef3c8cb79d/test/parallel/test-http-expect-continue.js#L35
Thanks tagros, I found a correct exemple there. Seems like attaching a listener to continue event flushes the headers. And it's documented.
Most helpful comment
In case it can help, here is the test that we have for this feature: https://github.com/nodejs/node/blob/1b2d3f7ae7f0391908b70b0333a5adef3c8cb79d/test/parallel/test-http-expect-continue.js#L35