From 49eb679674e3cdbf989a3f4a2fc67fa8c9803977 Mon Sep 17 00:00:00 2001 From: Miles Elam Date: Mon, 8 Jan 2018 00:11:05 -0800 Subject: [PATCH] http: process 100, 102-199 according to specs. Adding ServerResponse.writeProcessing to send 102 status codes. Added an `'information'` event to ClientRequest to handle 1xx status codes except 101 Upgrade. 101 Upgrade is excluded due to its non-informational processing according to RFC7231, Section 6.2.2. This affects several modules downstream that use the http module, e.g., node-fetch, all of whom violate HTTP RFCs due to this module. As such, this could introduce a breaking change for downstream if HTTP standards were ignored in an ad-hoc fashion. See also RFC2518 RFC8297. PR-URL: https://github.com/nodejs/node/pull/18033 Reviewed-By: Matteo Collina Reviewed-By: Ruben Bridgewater Reviewed-By: James M Snell Reviewed-By: Tiancheng "Timothy" Gu --- doc/api/http.md | 40 ++++++++++++++ lib/_http_client.js | 29 ++++++++--- lib/_http_server.js | 4 ++ .../test-http-information-processing.js | 52 +++++++++++++++++++ 4 files changed, 118 insertions(+), 7 deletions(-) create mode 100644 test/parallel/test-http-information-processing.js diff --git a/doc/api/http.md b/doc/api/http.md index 0a4fe959982480..74ba9e8792c4ef 100644 --- a/doc/api/http.md +++ b/doc/api/http.md @@ -400,6 +400,37 @@ Emitted when the server sends a '100 Continue' HTTP response, usually because the request contained 'Expect: 100-continue'. This is an instruction that the client should send the request body. +### Event: 'information' + + +Emitted when the server sends a 1xx response (excluding 101 Upgrade). This +event is emitted with a callback containing an object with a status code. + +```js +const http = require('http'); + +const options = { + hostname: '127.0.0.1', + port: 8080, + path: '/length_request' +}; + +// Make a request +const req = http.request(options); +req.end(); + +req.on('information', (res) => { + console.log('got information prior to main response: ' + res.statusCode); +}); +``` + +101 Upgrade statuses do not fire this event due to their break from the +traditional HTTP request/response chain, such as web sockets, in-place TLS +upgrades, or HTTP 2.0. To be notified of 101 Upgrade notices, listen for the +[`'upgrade'`][] event instead. + ### Event: 'response' + +Sends a HTTP/1.1 102 Processing message to the client, indicating that +the request body should be sent. + ## Class: http.IncomingMessage