• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1'use strict';
2
3const common = require('../common');
4const assert = require('assert');
5const http = require('http');
6const Countdown = require('../common/countdown');
7
8function explicit(req, res) {
9  assert.throws(() => {
10    res.writeHead(200, 'OK\r\nContent-Type: text/html\r\n');
11  }, /Invalid character in statusMessage/);
12
13  assert.throws(() => {
14    res.writeHead(200, 'OK\u010D\u010AContent-Type: gotcha\r\n');
15  }, /Invalid character in statusMessage/);
16
17  res.statusMessage = 'OK';
18  res.end();
19}
20
21function implicit(req, res) {
22  assert.throws(() => {
23    res.statusMessage = 'OK\r\nContent-Type: text/html\r\n';
24    res.writeHead(200);
25  }, /Invalid character in statusMessage/);
26  res.statusMessage = 'OK';
27  res.end();
28}
29
30const server = http.createServer((req, res) => {
31  if (req.url === '/explicit') {
32    explicit(req, res);
33  } else {
34    implicit(req, res);
35  }
36}).listen(0, common.mustCall(() => {
37  const hostname = 'localhost';
38  const countdown = new Countdown(2, () => server.close());
39  const url = `http://${hostname}:${server.address().port}`;
40  const check = common.mustCall((res) => {
41    assert.notStrictEqual(res.headers['content-type'], 'text/html');
42    assert.notStrictEqual(res.headers['content-type'], 'gotcha');
43    countdown.dec();
44  }, 2);
45  http.get(`${url}/explicit`, check).end();
46  http.get(`${url}/implicit`, check).end();
47}));
48