summaryrefslogtreecommitdiff
path: root/test/parallel/test-http-invalidheaderfield.js
blob: 01315ba69044a2ac1dc3495dd2444f29db666358 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
'use strict';
const common = require('../common');

const assert = require('assert');
const EventEmitter = require('events');
const http = require('http');

const ee = new EventEmitter();
let count = 3;

const server = http.createServer(function(req, res) {
  res.setHeader('testing_123', 123);
  assert.throws(function() {
    res.setHeader('testing 123', 123);
  }, TypeError);
  res.end('');
});
server.listen(0, function() {

  http.get({ port: this.address().port }, function() {
    ee.emit('done');
  });

  assert.throws(
    function() {
      const options = {
        port: server.address().port,
        headers: { 'testing 123': 123 }
      };
      http.get(options, common.mustNotCall());
    },
    function(err) {
      ee.emit('done');
      if (err instanceof TypeError) return true;
    }
  );

  // Should not throw.
  const options = {
    port: server.address().port,
    headers: { 'testing_123': 123 }
  };
  http.get(options, function() {
    ee.emit('done');
  });
});

ee.on('done', function() {
  if (--count === 0) {
    server.close();
  }
});