summaryrefslogtreecommitdiff
path: root/test/parallel/test-http-invalidheaderfield.js
blob: 9d4a12a952a83895a30b9d54324ebb0f2e92d02c (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
53
54
55
56
'use strict';
require('../common');
const assert = require('assert');
const EventEmitter = require('events');
const http = require('http');

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

const server = http.createServer(function(req, res) {
  assert.doesNotThrow(function() {
    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() {
      var options = {
        port: server.address().port,
        headers: {'testing 123': 123}
      };
      http.get(options, function() {});
    },
    function(err) {
      ee.emit('done');
      if (err instanceof TypeError) return true;
    }
  );

  assert.doesNotThrow(
    function() {
      var options = {
        port: server.address().port,
        headers: {'testing_123': 123}
      };
      http.get(options, function() {
        ee.emit('done');
      });
    }, TypeError
  );
});

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