diff options
author | Miles Elam <miles.elam@productops.com> | 2018-01-08 00:11:05 -0800 |
---|---|---|
committer | Matteo Collina <hello@matteocollina.com> | 2018-02-15 11:57:57 +0100 |
commit | baf84950781f253ab0244779a9e40b5dc0f4930e (patch) | |
tree | d58fc3d495bcd25ffc25914438c4c33348d37def /test/parallel/test-http-information-processing.js | |
parent | cfad44105d6baae44a7b5dd6ea179f7550a5038f (diff) | |
download | android-node-v8-baf84950781f253ab0244779a9e40b5dc0f4930e.tar.gz android-node-v8-baf84950781f253ab0244779a9e40b5dc0f4930e.tar.bz2 android-node-v8-baf84950781f253ab0244779a9e40b5dc0f4930e.zip |
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 <matteo.collina@gmail.com>
Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Tiancheng "Timothy" Gu <timothygu99@gmail.com>
Diffstat (limited to 'test/parallel/test-http-information-processing.js')
-rw-r--r-- | test/parallel/test-http-information-processing.js | 52 |
1 files changed, 52 insertions, 0 deletions
diff --git a/test/parallel/test-http-information-processing.js b/test/parallel/test-http-information-processing.js new file mode 100644 index 0000000000..af589477f0 --- /dev/null +++ b/test/parallel/test-http-information-processing.js @@ -0,0 +1,52 @@ +'use strict'; +require('../common'); +const assert = require('assert'); +const http = require('http'); +const Countdown = require('../common/countdown'); + +const test_res_body = 'other stuff!\n'; +const countdown = new Countdown(3, () => server.close()); + +const server = http.createServer((req, res) => { + console.error('Server sending informational message #1...'); + res.writeProcessing(); + console.error('Server sending informational message #2...'); + res.writeProcessing(); + console.error('Server sending full response...'); + res.writeHead(200, { + 'Content-Type': 'text/plain', + 'ABCD': '1' + }); + res.end(test_res_body); +}); + +server.listen(0, function() { + const req = http.request({ + port: this.address().port, + path: '/world' + }); + req.end(); + console.error('Client sending request...'); + + let body = ''; + + req.on('information', function(res) { + console.error('Client got 102 Processing...'); + countdown.dec(); + }); + + req.on('response', function(res) { + assert.strictEqual(countdown.remaining, 1, + 'Full response received before all 102 Processing'); + assert.strictEqual(200, res.statusCode, + `Final status code was ${res.statusCode}, not 200.`); + res.setEncoding('utf8'); + res.on('data', function(chunk) { body += chunk; }); + res.on('end', function() { + console.error('Got full response.'); + assert.strictEqual(body, test_res_body); + assert.ok('abcd' in res.headers); + countdown.dec(); + }); + }); +}); |