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