• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1'use strict';
2
3const common = require('../common');
4const assert = require('assert');
5
6const http = require('http');
7const net = require('net');
8
9function serverHandler(server, msg) {
10  const client = net.connect(server.address().port, 'localhost');
11
12  let response = '';
13
14  client.on('data', common.mustCall((chunk) => {
15    response += chunk.toString('utf-8');
16  }));
17
18  client.setEncoding('utf8');
19  client.on('error', common.mustNotCall());
20  client.on('end', common.mustCall(() => {
21    assert.strictEqual(
22      response,
23      'HTTP/1.1 400 Bad Request\r\nConnection: close\r\n\r\n'
24    );
25    server.close();
26  }));
27  client.write(msg);
28  client.resume();
29}
30
31{
32  const msg = [
33    'GET / HTTP/1.1',
34    'Host: localhost',
35    'Dummy: x\nContent-Length: 23',
36    '',
37    'GET / HTTP/1.1',
38    'Dummy: GET /admin HTTP/1.1',
39    'Host: localhost',
40    '',
41    '',
42  ].join('\r\n');
43
44  const server = http.createServer(common.mustNotCall());
45
46  server.listen(0, common.mustSucceed(serverHandler.bind(null, server, msg)));
47}
48
49{
50  const msg = [
51    'POST / HTTP/1.1',
52    'Host: localhost',
53    'x:x\nTransfer-Encoding: chunked',
54    '',
55    '1',
56    'A',
57    '0',
58    '',
59    '',
60  ].join('\r\n');
61
62  const server = http.createServer(common.mustNotCall());
63
64  server.listen(0, common.mustSucceed(serverHandler.bind(null, server, msg)));
65}
66
67{
68  const msg = [
69    'POST / HTTP/1.1',
70    'Host: localhost',
71    'x:\nTransfer-Encoding: chunked',
72    '',
73    '1',
74    'A',
75    '0',
76    '',
77    '',
78  ].join('\r\n');
79
80  const server = http.createServer(common.mustNotCall());
81
82  server.listen(0, common.mustSucceed(serverHandler.bind(null, server, msg)));
83}
84