11cb0ef41Sopenharmony_ci'use strict';
21cb0ef41Sopenharmony_cirequire('../common');
31cb0ef41Sopenharmony_ciconst assert = require('assert');
41cb0ef41Sopenharmony_ci
51cb0ef41Sopenharmony_ciconst http = require('http');
61cb0ef41Sopenharmony_ciconst OutgoingMessage = http.OutgoingMessage;
71cb0ef41Sopenharmony_ciconst ClientRequest = http.ClientRequest;
81cb0ef41Sopenharmony_ciconst ServerResponse = http.ServerResponse;
91cb0ef41Sopenharmony_ci
101cb0ef41Sopenharmony_ciassert.strictEqual(
111cb0ef41Sopenharmony_ci  typeof ClientRequest.prototype._implicitHeader, 'function');
121cb0ef41Sopenharmony_ciassert.strictEqual(
131cb0ef41Sopenharmony_ci  typeof ServerResponse.prototype._implicitHeader, 'function');
141cb0ef41Sopenharmony_ci
151cb0ef41Sopenharmony_ci// validateHeader
161cb0ef41Sopenharmony_ciassert.throws(() => {
171cb0ef41Sopenharmony_ci  const outgoingMessage = new OutgoingMessage();
181cb0ef41Sopenharmony_ci  outgoingMessage.setHeader();
191cb0ef41Sopenharmony_ci}, {
201cb0ef41Sopenharmony_ci  code: 'ERR_INVALID_HTTP_TOKEN',
211cb0ef41Sopenharmony_ci  name: 'TypeError',
221cb0ef41Sopenharmony_ci  message: 'Header name must be a valid HTTP token ["undefined"]'
231cb0ef41Sopenharmony_ci});
241cb0ef41Sopenharmony_ci
251cb0ef41Sopenharmony_ciassert.throws(() => {
261cb0ef41Sopenharmony_ci  const outgoingMessage = new OutgoingMessage();
271cb0ef41Sopenharmony_ci  outgoingMessage.setHeader('test');
281cb0ef41Sopenharmony_ci}, {
291cb0ef41Sopenharmony_ci  code: 'ERR_HTTP_INVALID_HEADER_VALUE',
301cb0ef41Sopenharmony_ci  name: 'TypeError',
311cb0ef41Sopenharmony_ci  message: 'Invalid value "undefined" for header "test"'
321cb0ef41Sopenharmony_ci});
331cb0ef41Sopenharmony_ci
341cb0ef41Sopenharmony_ciassert.throws(() => {
351cb0ef41Sopenharmony_ci  const outgoingMessage = new OutgoingMessage();
361cb0ef41Sopenharmony_ci  outgoingMessage.setHeader(404);
371cb0ef41Sopenharmony_ci}, {
381cb0ef41Sopenharmony_ci  code: 'ERR_INVALID_HTTP_TOKEN',
391cb0ef41Sopenharmony_ci  name: 'TypeError',
401cb0ef41Sopenharmony_ci  message: 'Header name must be a valid HTTP token ["404"]'
411cb0ef41Sopenharmony_ci});
421cb0ef41Sopenharmony_ci
431cb0ef41Sopenharmony_ciassert.throws(() => {
441cb0ef41Sopenharmony_ci  const outgoingMessage = new OutgoingMessage();
451cb0ef41Sopenharmony_ci  outgoingMessage.setHeader.call({ _header: 'test' }, 'test', 'value');
461cb0ef41Sopenharmony_ci}, {
471cb0ef41Sopenharmony_ci  code: 'ERR_HTTP_HEADERS_SENT',
481cb0ef41Sopenharmony_ci  name: 'Error',
491cb0ef41Sopenharmony_ci  message: 'Cannot set headers after they are sent to the client'
501cb0ef41Sopenharmony_ci});
511cb0ef41Sopenharmony_ci
521cb0ef41Sopenharmony_ciassert.throws(() => {
531cb0ef41Sopenharmony_ci  const outgoingMessage = new OutgoingMessage();
541cb0ef41Sopenharmony_ci  outgoingMessage.setHeader('200', 'あ');
551cb0ef41Sopenharmony_ci}, {
561cb0ef41Sopenharmony_ci  code: 'ERR_INVALID_CHAR',
571cb0ef41Sopenharmony_ci  name: 'TypeError',
581cb0ef41Sopenharmony_ci  message: 'Invalid character in header content ["200"]'
591cb0ef41Sopenharmony_ci});
601cb0ef41Sopenharmony_ci
611cb0ef41Sopenharmony_ci// write
621cb0ef41Sopenharmony_ci{
631cb0ef41Sopenharmony_ci  const outgoingMessage = new OutgoingMessage();
641cb0ef41Sopenharmony_ci
651cb0ef41Sopenharmony_ci  assert.throws(
661cb0ef41Sopenharmony_ci    () => {
671cb0ef41Sopenharmony_ci      outgoingMessage.write('');
681cb0ef41Sopenharmony_ci    },
691cb0ef41Sopenharmony_ci    {
701cb0ef41Sopenharmony_ci      code: 'ERR_METHOD_NOT_IMPLEMENTED',
711cb0ef41Sopenharmony_ci      name: 'Error',
721cb0ef41Sopenharmony_ci      message: 'The _implicitHeader() method is not implemented'
731cb0ef41Sopenharmony_ci    }
741cb0ef41Sopenharmony_ci  );
751cb0ef41Sopenharmony_ci}
761cb0ef41Sopenharmony_ci
771cb0ef41Sopenharmony_ciassert.throws(() => {
781cb0ef41Sopenharmony_ci  const outgoingMessage = new OutgoingMessage();
791cb0ef41Sopenharmony_ci  outgoingMessage.write.call({ _header: 'test', _hasBody: 'test' });
801cb0ef41Sopenharmony_ci}, {
811cb0ef41Sopenharmony_ci  code: 'ERR_INVALID_ARG_TYPE',
821cb0ef41Sopenharmony_ci  name: 'TypeError',
831cb0ef41Sopenharmony_ci  message: 'The "chunk" argument must be of type string or an instance of ' +
841cb0ef41Sopenharmony_ci           'Buffer or Uint8Array. Received undefined'
851cb0ef41Sopenharmony_ci});
861cb0ef41Sopenharmony_ci
871cb0ef41Sopenharmony_ciassert.throws(() => {
881cb0ef41Sopenharmony_ci  const outgoingMessage = new OutgoingMessage();
891cb0ef41Sopenharmony_ci  outgoingMessage.write.call({ _header: 'test', _hasBody: 'test' }, 1);
901cb0ef41Sopenharmony_ci}, {
911cb0ef41Sopenharmony_ci  code: 'ERR_INVALID_ARG_TYPE',
921cb0ef41Sopenharmony_ci  name: 'TypeError',
931cb0ef41Sopenharmony_ci  message: 'The "chunk" argument must be of type string or an instance of ' +
941cb0ef41Sopenharmony_ci           'Buffer or Uint8Array. Received type number (1)'
951cb0ef41Sopenharmony_ci});
961cb0ef41Sopenharmony_ci
971cb0ef41Sopenharmony_ciassert.throws(() => {
981cb0ef41Sopenharmony_ci  const outgoingMessage = new OutgoingMessage();
991cb0ef41Sopenharmony_ci  outgoingMessage.write.call({ _header: 'test', _hasBody: 'test' }, null);
1001cb0ef41Sopenharmony_ci}, {
1011cb0ef41Sopenharmony_ci  code: 'ERR_STREAM_NULL_VALUES',
1021cb0ef41Sopenharmony_ci  name: 'TypeError'
1031cb0ef41Sopenharmony_ci});
1041cb0ef41Sopenharmony_ci
1051cb0ef41Sopenharmony_ci// addTrailers()
1061cb0ef41Sopenharmony_ci// The `Error` comes from the JavaScript engine so confirm that it is a
1071cb0ef41Sopenharmony_ci// `TypeError` but do not check the message. It will be different in different
1081cb0ef41Sopenharmony_ci// JavaScript engines.
1091cb0ef41Sopenharmony_ciassert.throws(() => {
1101cb0ef41Sopenharmony_ci  const outgoingMessage = new OutgoingMessage();
1111cb0ef41Sopenharmony_ci  outgoingMessage.addTrailers();
1121cb0ef41Sopenharmony_ci}, TypeError);
1131cb0ef41Sopenharmony_ci
1141cb0ef41Sopenharmony_ciassert.throws(() => {
1151cb0ef41Sopenharmony_ci  const outgoingMessage = new OutgoingMessage();
1161cb0ef41Sopenharmony_ci  outgoingMessage.addTrailers({ 'あ': 'value' });
1171cb0ef41Sopenharmony_ci}, {
1181cb0ef41Sopenharmony_ci  code: 'ERR_INVALID_HTTP_TOKEN',
1191cb0ef41Sopenharmony_ci  name: 'TypeError',
1201cb0ef41Sopenharmony_ci  message: 'Trailer name must be a valid HTTP token ["あ"]'
1211cb0ef41Sopenharmony_ci});
1221cb0ef41Sopenharmony_ci
1231cb0ef41Sopenharmony_ciassert.throws(() => {
1241cb0ef41Sopenharmony_ci  const outgoingMessage = new OutgoingMessage();
1251cb0ef41Sopenharmony_ci  outgoingMessage.addTrailers({ 404: 'あ' });
1261cb0ef41Sopenharmony_ci}, {
1271cb0ef41Sopenharmony_ci  code: 'ERR_INVALID_CHAR',
1281cb0ef41Sopenharmony_ci  name: 'TypeError',
1291cb0ef41Sopenharmony_ci  message: 'Invalid character in trailer content ["404"]'
1301cb0ef41Sopenharmony_ci});
1311cb0ef41Sopenharmony_ci
1321cb0ef41Sopenharmony_ci{
1331cb0ef41Sopenharmony_ci  const outgoingMessage = new OutgoingMessage();
1341cb0ef41Sopenharmony_ci  assert.strictEqual(outgoingMessage.destroyed, false);
1351cb0ef41Sopenharmony_ci  outgoingMessage.destroy();
1361cb0ef41Sopenharmony_ci  assert.strictEqual(outgoingMessage.destroyed, true);
1371cb0ef41Sopenharmony_ci}
138