Node: Sending HTTP request with 'Expect: 100-continue'

Created on 28 Dec 2016  路  4Comments  路  Source: nodejs/node

  • Version: v7.3.0
  • Platform: Linux laptop1 3.16.0-4-amd64 # 1 SMP Debian 3.16.36-1+deb8u2 (2016-10-19) x86_64 GNU/Linux

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?

http question

Most helpful comment

All 4 comments

Have you looked into the checkContinue event on the HTTP server instance?

check continue docs

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)
})

Thanks tagros, I found a correct exemple there. Seems like attaching a listener to continue event flushes the headers. And it's documented.

Was this page helpful?
0 / 5 - 0 ratings