• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1'use strict';
2const common = require('../common');
3
4const net = require('net');
5const { HTTPParser } = process.binding('http_parser');
6
7const server = net.createServer((socket) => {
8  socket.write('HTTP/1.1 200 OK\r\n');
9  socket.write('Transfer-Encoding: chunked\r\n\r\n');
10  setTimeout(() => {
11    socket.write('1\r\n');
12    socket.write('\n\r\n');
13    setTimeout(() => {
14      socket.write('1\r\n');
15      socket.write('\n\r\n');
16      setImmediate(() => {
17        socket.destroy();
18        server.close();
19      });
20    }, 500);
21  }, 500);
22}).listen(0, () => {
23  const socket = net.connect(server.address().port);
24  const parser = new HTTPParser(HTTPParser.RESPONSE, false);
25  parser.initialize(
26    HTTPParser.RESPONSE,
27    {},
28    0,
29    false,
30    1e3
31  );
32
33  parser[HTTPParser.kOnTimeout] = common.mustNotCall();
34
35  parser[HTTPParser.kOnHeaders] = common.mustNotCall();
36
37  parser[HTTPParser.kOnExecute] = common.mustCallAtLeast(3);
38
39  parser[HTTPParser.kOnHeadersComplete] = common.mustCall();
40
41  parser[HTTPParser.kOnBody] = common.mustCall(2);
42
43  parser[HTTPParser.kOnMessageComplete] = common.mustNotCall();
44
45  parser.consume(socket._handle);
46});
47