1'use strict';
2
3const common = require('../common');
4const assert = require('assert');
5
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: chunkedchunked',
13  '',
14  '1',
15  'A',
16  '0',
17  '',
18].join('\r\n');
19
20const server = http.createServer(common.mustCall((req, res) => {
21  // Verify that no data is received
22
23  req.on('data', common.mustNotCall());
24
25  req.on('end', common.mustNotCall(() => {
26    res.writeHead(200, { 'Content-Type': 'text/plain' });
27    res.end();
28  }));
29}, 1));
30
31server.listen(0, common.mustSucceed(() => {
32  const client = net.connect(server.address().port, 'localhost');
33
34  let response = '';
35
36  client.on('data', common.mustCall((chunk) => {
37    response += chunk;
38  }));
39
40  client.setEncoding('utf8');
41  client.on('error', common.mustNotCall());
42  client.on('end', common.mustCall(() => {
43    assert.strictEqual(
44      response,
45      'HTTP/1.1 400 Bad Request\r\nConnection: close\r\n\r\n'
46    );
47    server.close();
48  }));
49  client.write(msg);
50  client.resume();
51}));
52