0
0
mirror of https://github.com/nodejs/node.git synced 2024-11-21 21:19:50 +01:00
nodejs/test/parallel/test-http-server-keepalive-end.js
Rich Trott 330f25ef82 test: prepare for consistent comma-dangle lint rule
Make changes so that tests will pass when the comma-dangle settings
applied to the rest of the code base are also applied to tests.

PR-URL: https://github.com/nodejs/node/pull/37930
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Derek Lewis <DerekNonGeneric@inf.is>
2021-04-01 23:14:29 -07:00

39 lines
1001 B
JavaScript

'use strict';
const common = require('../common');
const assert = require('assert');
const { createServer } = require('http');
const { connect } = require('net');
// Make sure that for HTTP keepalive requests, the .on('end') event is emitted
// on the incoming request object, and that the parser instance does not hold
// on to that request object afterwards.
const server = createServer(common.mustCall((req, res) => {
req.on('end', common.mustCall(() => {
const parser = req.socket.parser;
assert.strictEqual(parser.incoming, req);
process.nextTick(() => {
assert.strictEqual(parser.incoming, null);
});
}));
res.end('hello world');
}));
server.unref();
server.listen(0, common.mustCall(() => {
const client = connect(server.address().port);
const req = [
'POST / HTTP/1.1',
`Host: localhost:${server.address().port}`,
'Connection: keep-alive',
'Content-Length: 11',
'',
'hello world',
'',
].join('\r\n');
client.end(req);
}));