• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1'use strict';
2const common = require('../common');
3const assert = require('assert');
4const http = require('http');
5const net = require('net');
6
7const response = Buffer.from('HTTP/1.1 200 OK\r\n' +
8  'Content-Length: 6\r\n' +
9  'Transfer-Encoding: Chunked\r\n' +
10  '\r\n' +
11  '6\r\nfoobar' +
12  '0\r\n');
13
14const server = net.createServer(common.mustCall((conn) => {
15  conn.write(response);
16}));
17
18server.listen(0, common.mustCall(() => {
19  const req = http.get(`http://localhost:${server.address().port}/`);
20  req.end();
21  req.on('error', common.mustCall((err) => {
22    const reason = 'Content-Length can\'t be present with Transfer-Encoding';
23    assert.strictEqual(err.message, `Parse Error: ${reason}`);
24    assert(err.bytesParsed < response.length);
25    assert(err.bytesParsed >= response.indexOf('Transfer-Encoding'));
26    assert.strictEqual(err.code, 'HPE_UNEXPECTED_CONTENT_LENGTH');
27    assert.strictEqual(err.reason, reason);
28    assert.deepStrictEqual(err.rawPacket, response);
29
30    server.close();
31  }));
32}));
33