• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1'use strict';
2const common = require('../common');
3const assert = require('assert');
4const { createServer } = require('http');
5const { connect } = require('net');
6
7// Make sure that for HTTP keepalive requests, the .on('end') event is emitted
8// on the incoming request object, and that the parser instance does not hold
9// on to that request object afterwards.
10
11const server = createServer(common.mustCall((req, res) => {
12  req.on('end', common.mustCall(() => {
13    const parser = req.socket.parser;
14    assert.strictEqual(parser.incoming, req);
15    process.nextTick(() => {
16      assert.strictEqual(parser.incoming, null);
17    });
18  }));
19  res.end('hello world');
20}));
21
22server.unref();
23
24server.listen(0, common.mustCall(() => {
25  const client = connect(server.address().port);
26
27  const req = [
28    'POST / HTTP/1.1',
29    `Host: localhost:${server.address().port}`,
30    'Connection: keep-alive',
31    'Content-Length: 11',
32    '',
33    'hello world',
34    '',
35  ].join('\r\n');
36
37  client.end(req);
38}));
39