• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1'use strict';
2
3const common = require('../common');
4
5const assert = require('assert');
6const http = require('http');
7const net = require('net');
8
9const msg = [
10  'POST / HTTP/1.1',
11  'Host: 127.0.0.1',
12  'Transfer-Encoding: chunked',
13  'Transfer-Encoding: chunked-false',
14  'Connection: upgrade',
15  '',
16  '1',
17  'A',
18  '0',
19  '',
20  'GET /flag HTTP/1.1',
21  'Host: 127.0.0.1',
22  '',
23  '',
24].join('\r\n');
25
26// Verify that the server is called only once even with a smuggled request.
27
28const server = http.createServer(common.mustCall((req, res) => {
29  res.end();
30}, 1));
31
32function send(next) {
33  const client = net.connect(server.address().port, 'localhost');
34  client.setEncoding('utf8');
35  client.on('error', common.mustNotCall());
36  client.on('end', next);
37  client.write(msg);
38  client.resume();
39}
40
41server.listen(0, common.mustCall((err) => {
42  assert.ifError(err);
43  send(common.mustCall(() => {
44    server.close();
45  }));
46}));
47