• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1'use strict';
2const common = require('../common');
3
4const assert = require('assert');
5const EventEmitter = require('events');
6const http = require('http');
7
8const ee = new EventEmitter();
9let count = 3;
10
11const server = http.createServer(function(req, res) {
12  res.setHeader('testing_123', 123);
13  assert.throws(function() {
14    res.setHeader('testing 123', 123);
15  }, TypeError);
16  res.end('');
17});
18server.listen(0, function() {
19
20  http.get({ port: this.address().port }, function() {
21    ee.emit('done');
22  });
23
24  assert.throws(
25    function() {
26      const options = {
27        port: server.address().port,
28        headers: { 'testing 123': 123 }
29      };
30      http.get(options, common.mustNotCall());
31    },
32    function(err) {
33      ee.emit('done');
34      if (err instanceof TypeError) return true;
35    }
36  );
37
38  // Should not throw.
39  const options = {
40    port: server.address().port,
41    headers: { 'testing_123': 123 }
42  };
43  http.get(options, function() {
44    ee.emit('done');
45  });
46});
47
48ee.on('done', function() {
49  if (--count === 0) {
50    server.close();
51  }
52});
53