Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

Support for "Expect: 100-continue" #611

Open
aseemk opened this Issue · 1 comment

3 participants

@aseemk

You probably already know what this is, but if not, a client can send an Expect: 100-continue request header, giving the server a chance to respond either with 100 Continue or a different, final status code, before the client sends along the request body.

http://www.w3.org/Protocols/rfc2616/rfc2616-sec8.html

E.g. Amazon S3 recommends using this:

http://docs.aws.amazon.com/AmazonS3/latest/dev/RESTRedirect.html

Node supports this perfectly in core -- if it sees an Expect: 100-continue client request header, it'll send the headers right away, and emit a continue event if/when the server responds with 100 Continue.

http://nodejs.org/api/http.html#http_event_continue

If the server responds with something else, e.g. a redirect or an error, that's a regular response event. And for robustness, the caller should also set a timeout to go ahead send the request body if the server doesn't respond.

Usually, when sending Expect: 100-continue, you should both set a timeout and listen for the continue event.

Conceptually, supporting this is straightforward: if the request headers include Expect: 100-continue, don't write the request body right away, and instead set this listener and timeout.

var written = false;

function writeBody() {
  if (written) { return; }
  written = true;
  // write body here
}

req.on('continue', writeBody);
setTimeout(writeBody, 500);

But I know it might be trickier in practice with the details. =)

Hope this helps either way, and thanks for the consideration!

@patrickod

+1 would love to see this

@mikeal mikeal added the NeedsCode label
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.