1'use strict';
2
3const common = require('../common');
4const http = require('http');
5const net = require('net');
6const assert = require('assert');
7
8const reqstr = 'HTTP/1.1 200 OK\r\n' +
9               'Content-Length: 1\r\n' +
10               'Transfer-Encoding: chunked\r\n\r\n';
11
12const server = net.createServer((socket) => {
13  socket.write(reqstr);
14});
15
16server.listen(0, () => {
17  // The callback should not be called because the server is sending
18  // both a Content-Length header and a Transfer-Encoding: chunked
19  // header, which is a violation of the HTTP spec.
20  const req = http.get({ port: server.address().port }, common.mustNotCall());
21  req.on('error', common.mustCall((err) => {
22    assert.match(err.message, /^Parse Error/);
23    assert.strictEqual(err.code, 'HPE_UNEXPECTED_CONTENT_LENGTH');
24    server.close();
25  }));
26});
27