11cb0ef41Sopenharmony_ci'use strict';
21cb0ef41Sopenharmony_ci
31cb0ef41Sopenharmony_ciconst common = require('../common');
41cb0ef41Sopenharmony_ciconst assert = require('assert');
51cb0ef41Sopenharmony_ciconst http = require('http');
61cb0ef41Sopenharmony_ciconst Countdown = require('../common/countdown');
71cb0ef41Sopenharmony_ci
81cb0ef41Sopenharmony_cifunction explicit(req, res) {
91cb0ef41Sopenharmony_ci  assert.throws(() => {
101cb0ef41Sopenharmony_ci    res.writeHead(200, 'OK\r\nContent-Type: text/html\r\n');
111cb0ef41Sopenharmony_ci  }, /Invalid character in statusMessage/);
121cb0ef41Sopenharmony_ci
131cb0ef41Sopenharmony_ci  assert.throws(() => {
141cb0ef41Sopenharmony_ci    res.writeHead(200, 'OK\u010D\u010AContent-Type: gotcha\r\n');
151cb0ef41Sopenharmony_ci  }, /Invalid character in statusMessage/);
161cb0ef41Sopenharmony_ci
171cb0ef41Sopenharmony_ci  res.statusMessage = 'OK';
181cb0ef41Sopenharmony_ci  res.end();
191cb0ef41Sopenharmony_ci}
201cb0ef41Sopenharmony_ci
211cb0ef41Sopenharmony_cifunction implicit(req, res) {
221cb0ef41Sopenharmony_ci  assert.throws(() => {
231cb0ef41Sopenharmony_ci    res.statusMessage = 'OK\r\nContent-Type: text/html\r\n';
241cb0ef41Sopenharmony_ci    res.writeHead(200);
251cb0ef41Sopenharmony_ci  }, /Invalid character in statusMessage/);
261cb0ef41Sopenharmony_ci  res.statusMessage = 'OK';
271cb0ef41Sopenharmony_ci  res.end();
281cb0ef41Sopenharmony_ci}
291cb0ef41Sopenharmony_ci
301cb0ef41Sopenharmony_ciconst server = http.createServer((req, res) => {
311cb0ef41Sopenharmony_ci  if (req.url === '/explicit') {
321cb0ef41Sopenharmony_ci    explicit(req, res);
331cb0ef41Sopenharmony_ci  } else {
341cb0ef41Sopenharmony_ci    implicit(req, res);
351cb0ef41Sopenharmony_ci  }
361cb0ef41Sopenharmony_ci}).listen(0, common.mustCall(() => {
371cb0ef41Sopenharmony_ci  const hostname = 'localhost';
381cb0ef41Sopenharmony_ci  const countdown = new Countdown(2, () => server.close());
391cb0ef41Sopenharmony_ci  const url = `http://${hostname}:${server.address().port}`;
401cb0ef41Sopenharmony_ci  const check = common.mustCall((res) => {
411cb0ef41Sopenharmony_ci    assert.notStrictEqual(res.headers['content-type'], 'text/html');
421cb0ef41Sopenharmony_ci    assert.notStrictEqual(res.headers['content-type'], 'gotcha');
431cb0ef41Sopenharmony_ci    countdown.dec();
441cb0ef41Sopenharmony_ci  }, 2);
451cb0ef41Sopenharmony_ci  http.get(`${url}/explicit`, check).end();
461cb0ef41Sopenharmony_ci  http.get(`${url}/implicit`, check).end();
471cb0ef41Sopenharmony_ci}));
48