diff options
author | Austin Wright <aaa@bzfx.net> | 2019-09-21 17:30:29 -0700 |
---|---|---|
committer | Rich Trott <rtrott@gmail.com> | 2019-10-05 17:43:42 -0700 |
commit | 28c3a9dd723e124a0e38588826c737eee7bfded5 (patch) | |
tree | b59f6a6192ce9fcd7e8433e8ae2bcc4fd7550f75 /test | |
parent | f58e8eb103ff30876198946a4a9c1280b987c1fb (diff) | |
download | android-node-v8-28c3a9dd723e124a0e38588826c737eee7bfded5.tar.gz android-node-v8-28c3a9dd723e124a0e38588826c737eee7bfded5.tar.bz2 android-node-v8-28c3a9dd723e124a0e38588826c737eee7bfded5.zip |
test: add test for HTTP server response with Connection: close
PR-URL: https://github.com/nodejs/node/pull/29836
Refs: https://github.com/nodejs/node/issues/29758
Refs: https://github.com/nodejs/node/pull/29649
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Minwoo Jung <minwoo@nodesource.com>
Diffstat (limited to 'test')
-rw-r--r-- | test/parallel/test-http-generic-streams.js | 80 |
1 files changed, 80 insertions, 0 deletions
diff --git a/test/parallel/test-http-generic-streams.js b/test/parallel/test-http-generic-streams.js index bc28d1fcd4..aea371432a 100644 --- a/test/parallel/test-http-generic-streams.js +++ b/test/parallel/test-http-generic-streams.js @@ -23,6 +23,7 @@ const MakeDuplexPair = require('../common/duplexpair'); res.on('data', common.mustCall((data) => { assert.strictEqual(data, testData); })); + res.on('end', common.mustCall()); })); req.end(); } @@ -58,3 +59,82 @@ const MakeDuplexPair = require('../common/duplexpair'); doRequest(); }); } + +// Test 3: Connection: close request/response with chunked +{ + const testData = 'Hello, World!\n'; + const server = http.createServer(common.mustCall((req, res) => { + req.setEncoding('utf8'); + req.resume(); + req.on('data', common.mustCall(function test3_req_data(data) { + assert.strictEqual(data, testData); + })); + req.once('end', function() { + res.statusCode = 200; + res.setHeader('Content-Type', 'text/plain'); + res.write(testData); + res.end(); + }); + })); + + const { clientSide, serverSide } = MakeDuplexPair(); + server.emit('connection', serverSide); + clientSide.on('end', common.mustCall()); + serverSide.on('end', common.mustCall()); + + const req = http.request({ + createConnection: common.mustCall(() => clientSide), + method: 'PUT', + headers: { 'Connection': 'close' } + }, common.mustCall((res) => { + res.setEncoding('utf8'); + res.on('data', common.mustCall(function test3_res_data(data) { + assert.strictEqual(data, testData); + })); + res.on('end', common.mustCall()); + })); + req.write(testData); + req.end(); +} + +// Test 4: Connection: close request/response with Content-Length +// The same as Test 3, but with Content-Length headers +{ + const testData = 'Hello, World!\n'; + const server = http.createServer(common.mustCall((req, res) => { + assert.strictEqual(req.headers['content-length'], testData.length + ''); + req.setEncoding('utf8'); + req.on('data', common.mustCall(function test4_req_data(data) { + assert.strictEqual(data, testData); + })); + req.once('end', function() { + res.statusCode = 200; + res.setHeader('Content-Type', 'text/plain'); + res.setHeader('Content-Length', testData.length); + res.write(testData); + res.end(); + }); + + })); + + const { clientSide, serverSide } = MakeDuplexPair(); + server.emit('connection', serverSide); + clientSide.on('end', common.mustCall()); + serverSide.on('end', common.mustCall()); + + const req = http.request({ + createConnection: common.mustCall(() => clientSide), + method: 'PUT', + headers: { 'Connection': 'close' } + }, common.mustCall((res) => { + res.setEncoding('utf8'); + assert.strictEqual(res.headers['content-length'], testData.length + ''); + res.on('data', common.mustCall(function test4_res_data(data) { + assert.strictEqual(data, testData); + })); + res.on('end', common.mustCall()); + })); + req.setHeader('Content-Length', testData.length); + req.write(testData); + req.end(); +} |