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