1// Flags: --expose-internals
2
3'use strict';
4
5const common = require('../common');
6const assert = require('assert');
7const { fork } = require('child_process');
8const http = require('http');
9
10if (process.argv[2] === 'child') {
11  process.once('message', (req, socket) => {
12    const res = new http.ServerResponse(req);
13    res.assignSocket(socket);
14    res.end();
15  });
16
17  process.send('ready');
18  return;
19}
20
21const { kTimeout } = require('internal/timers');
22
23let child;
24let socket;
25
26const server = http.createServer(common.mustCall((req, res) => {
27  const r = {
28    method: req.method,
29    headers: req.headers,
30    path: req.path,
31    httpVersionMajor: req.httpVersionMajor,
32    query: req.query,
33  };
34
35  socket = res.socket;
36  child.send(r, socket);
37  server.close();
38}));
39
40server.listen(0, common.mustCall(() => {
41  child = fork(__filename, [ 'child' ]);
42  child.once('message', (msg) => {
43    assert.strictEqual(msg, 'ready');
44    const req = http.request({
45      port: server.address().port,
46    }, common.mustCall((res) => {
47      res.on('data', () => {});
48      res.on('end', common.mustCall(() => {
49        assert.strictEqual(socket[kTimeout], null);
50        assert.strictEqual(socket.parser, null);
51        assert.strictEqual(socket._httpMessage, null);
52      }));
53    }));
54
55    req.end();
56  });
57}));
58