From f612a6dd5cb17d8a6bd6b6332348b94839cf2ed0 Mon Sep 17 00:00:00 2001 From: Anatoli Papirovski Date: Wed, 30 Aug 2017 10:12:24 -0400 Subject: [PATCH] http2: handle 100-continue flow & writeContinue Adds an implementation for writeContinue based on the h2 spec & the existing http implementation. ClientHttp2Stream now also emits a continue event when it receives headers with :status 100. Includes two test cases for default server continue behaviour and for the exposed checkContinue listener. PR-URL: https://github.com/nodejs/node/pull/15039 Reviewed-By: Matteo Collina Reviewed-By: James M Snell --- doc/api/http2.md | 62 +++++++++++++- lib/internal/http2/compat.js | 11 ++- lib/internal/http2/core.js | 8 ++ ...test-http2-compat-expect-continue-check.js | 81 +++++++++++++++++++ .../test-http2-compat-expect-continue.js | 66 +++++++++++++++ 5 files changed, 223 insertions(+), 5 deletions(-) create mode 100644 test/parallel/test-http2-compat-expect-continue-check.js create mode 100644 test/parallel/test-http2-compat-expect-continue.js diff --git a/doc/api/http2.md b/doc/api/http2.md index 72ca5cc806950c..8d521705a7fa03 100755 --- a/doc/api/http2.md +++ b/doc/api/http2.md @@ -849,6 +849,15 @@ used exclusively on HTTP/2 Clients. `Http2Stream` instances on the client provide events such as `'response'` and `'push'` that are only relevant on the client. +#### Event: 'continue' + + +Emitted when the server sends a `100 Continue` status, usually because +the request contained `Expect: 100-continue`. This is an instruction that +the client should send the request body. + #### Event: 'headers' + +* `request` {http2.Http2ServerRequest} +* `response` {http2.Http2ServerResponse} + +If a [`'request'`][] listener is registered or [`'http2.createServer()'`][] is +supplied a callback function, the `'checkContinue'` event is emitted each time +a request with an HTTP `Expect: 100-continue` is received. If this event is +not listened for, the server will automatically respond with a status +`100 Continue` as appropriate. + +Handling this event involves calling [`response.writeContinue()`][] if the client +should continue to send the request body, or generating an appropriate HTTP +response (e.g. 400 Bad Request) if the client should not continue to send the +request body. + +Note that when this event is emitted and handled, the [`'request'`][] event will +not be emitted. + ### Class: Http2SecureServer +#### Event: 'checkContinue' + + +* `request` {http2.Http2ServerRequest} +* `response` {http2.Http2ServerResponse} + +If a [`'request'`][] listener is registered or [`'http2.createSecureServer()'`][] +is supplied a callback function, the `'checkContinue'` event is emitted each +time a request with an HTTP `Expect: 100-continue` is received. If this event +is not listened for, the server will automatically respond with a status +`100 Continue` as appropriate. + +Handling this event involves calling [`response.writeContinue()`][] if the client +should continue to send the request body, or generating an appropriate HTTP +response (e.g. 400 Bad Request) if the client should not continue to send the +request body. + +Note that when this event is emitted and handled, the [`'request'`][] event will +not be emitted. + ### http2.createServer(options[, onRequestHandler]) -Throws an error as the `'continue'` flow is not current implemented. Added for -parity with [HTTP/1](). +Sends a status `100 Continue` to the client, indicating that the request body +should be sent. See the [`'checkContinue'`][] event on `Http2Server` and +`Http2SecureServer`. ### response.writeHead(statusCode[, statusMessage][, headers])