From 28c3a9dd723e124a0e38588826c737eee7bfded5 Mon Sep 17 00:00:00 2001 From: Austin Wright Date: Sat, 21 Sep 2019 17:30:29 -0700 Subject: 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 Reviewed-By: Luigi Pinca Reviewed-By: James M Snell Reviewed-By: Minwoo Jung --- test/parallel/test-http-generic-streams.js | 80 ++++++++++++++++++++++++++++++ 1 file changed, 80 insertions(+) (limited to 'test') 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(); +} -- cgit v1.2.3