• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1'use strict';
2
3const common = require('../common');
4const http = require('http');
5const assert = require('assert');
6
7// TODO(@jasnell) At some point this should be refactored as the API should not
8// be allowing users to set multiple content-length values in the first place.
9
10function test(server) {
11  server.listen(0, common.mustCall(() => {
12    http.get(
13      { port: server.address().port },
14      () => { assert.fail('Client allowed multiple content-length headers.'); }
15    ).on('error', common.mustCall((err) => {
16      assert.ok(err.message.startsWith('Parse Error'), err.message);
17      assert.strictEqual(err.code, 'HPE_UNEXPECTED_CONTENT_LENGTH');
18      server.close();
19    }));
20  }));
21}
22
23// Test adding an extra content-length header using setHeader().
24{
25  const server = http.createServer((req, res) => {
26    res.setHeader('content-length', [2, 1]);
27    res.end('ok');
28  });
29
30  test(server);
31}
32
33// Test adding an extra content-length header using writeHead().
34{
35  const server = http.createServer((req, res) => {
36    res.writeHead(200, { 'content-length': [1, 2] });
37    res.end('ok');
38  });
39
40  test(server);
41}
42