11cb0ef41Sopenharmony_ci'use strict'; 21cb0ef41Sopenharmony_ciconst common = require('../common'); 31cb0ef41Sopenharmony_ciconst http = require('http'); 41cb0ef41Sopenharmony_ciconst assert = require('assert'); 51cb0ef41Sopenharmony_ci 61cb0ef41Sopenharmony_ci{ 71cb0ef41Sopenharmony_ci const server = http.createServer({ requireHostHeader: false }, common.mustCall((req, res) => { 81cb0ef41Sopenharmony_ci res.writeHead(200); // Headers already sent 91cb0ef41Sopenharmony_ci const headers = new globalThis.Headers({ foo: '1' }); 101cb0ef41Sopenharmony_ci assert.throws(() => { 111cb0ef41Sopenharmony_ci res.setHeaders(headers); 121cb0ef41Sopenharmony_ci }, { 131cb0ef41Sopenharmony_ci code: 'ERR_HTTP_HEADERS_SENT' 141cb0ef41Sopenharmony_ci }); 151cb0ef41Sopenharmony_ci res.end(); 161cb0ef41Sopenharmony_ci })); 171cb0ef41Sopenharmony_ci 181cb0ef41Sopenharmony_ci server.listen(0, common.mustCall(() => { 191cb0ef41Sopenharmony_ci http.get({ port: server.address().port }, (res) => { 201cb0ef41Sopenharmony_ci assert.strictEqual(res.headers.foo, undefined); 211cb0ef41Sopenharmony_ci res.resume().on('end', common.mustCall(() => { 221cb0ef41Sopenharmony_ci server.close(); 231cb0ef41Sopenharmony_ci })); 241cb0ef41Sopenharmony_ci }); 251cb0ef41Sopenharmony_ci })); 261cb0ef41Sopenharmony_ci} 271cb0ef41Sopenharmony_ci 281cb0ef41Sopenharmony_ci{ 291cb0ef41Sopenharmony_ci const server = http.createServer({ requireHostHeader: false }, common.mustCall((req, res) => { 301cb0ef41Sopenharmony_ci assert.throws(() => { 311cb0ef41Sopenharmony_ci res.setHeaders(['foo', '1']); 321cb0ef41Sopenharmony_ci }, { 331cb0ef41Sopenharmony_ci code: 'ERR_INVALID_ARG_TYPE' 341cb0ef41Sopenharmony_ci }); 351cb0ef41Sopenharmony_ci assert.throws(() => { 361cb0ef41Sopenharmony_ci res.setHeaders({ foo: '1' }); 371cb0ef41Sopenharmony_ci }, { 381cb0ef41Sopenharmony_ci code: 'ERR_INVALID_ARG_TYPE' 391cb0ef41Sopenharmony_ci }); 401cb0ef41Sopenharmony_ci assert.throws(() => { 411cb0ef41Sopenharmony_ci res.setHeaders(null); 421cb0ef41Sopenharmony_ci }, { 431cb0ef41Sopenharmony_ci code: 'ERR_INVALID_ARG_TYPE' 441cb0ef41Sopenharmony_ci }); 451cb0ef41Sopenharmony_ci assert.throws(() => { 461cb0ef41Sopenharmony_ci res.setHeaders(undefined); 471cb0ef41Sopenharmony_ci }, { 481cb0ef41Sopenharmony_ci code: 'ERR_INVALID_ARG_TYPE' 491cb0ef41Sopenharmony_ci }); 501cb0ef41Sopenharmony_ci assert.throws(() => { 511cb0ef41Sopenharmony_ci res.setHeaders('test'); 521cb0ef41Sopenharmony_ci }, { 531cb0ef41Sopenharmony_ci code: 'ERR_INVALID_ARG_TYPE' 541cb0ef41Sopenharmony_ci }); 551cb0ef41Sopenharmony_ci assert.throws(() => { 561cb0ef41Sopenharmony_ci res.setHeaders(1); 571cb0ef41Sopenharmony_ci }, { 581cb0ef41Sopenharmony_ci code: 'ERR_INVALID_ARG_TYPE' 591cb0ef41Sopenharmony_ci }); 601cb0ef41Sopenharmony_ci res.end(); 611cb0ef41Sopenharmony_ci })); 621cb0ef41Sopenharmony_ci 631cb0ef41Sopenharmony_ci server.listen(0, common.mustCall(() => { 641cb0ef41Sopenharmony_ci http.get({ port: server.address().port }, (res) => { 651cb0ef41Sopenharmony_ci assert.strictEqual(res.headers.foo, undefined); 661cb0ef41Sopenharmony_ci res.resume().on('end', common.mustCall(() => { 671cb0ef41Sopenharmony_ci server.close(); 681cb0ef41Sopenharmony_ci })); 691cb0ef41Sopenharmony_ci }); 701cb0ef41Sopenharmony_ci })); 711cb0ef41Sopenharmony_ci} 721cb0ef41Sopenharmony_ci 731cb0ef41Sopenharmony_ci{ 741cb0ef41Sopenharmony_ci const server = http.createServer({ requireHostHeader: false }, common.mustCall((req, res) => { 751cb0ef41Sopenharmony_ci const headers = new globalThis.Headers({ foo: '1', bar: '2' }); 761cb0ef41Sopenharmony_ci res.setHeaders(headers); 771cb0ef41Sopenharmony_ci res.writeHead(200); 781cb0ef41Sopenharmony_ci res.end(); 791cb0ef41Sopenharmony_ci })); 801cb0ef41Sopenharmony_ci 811cb0ef41Sopenharmony_ci server.listen(0, common.mustCall(() => { 821cb0ef41Sopenharmony_ci http.get({ port: server.address().port }, (res) => { 831cb0ef41Sopenharmony_ci assert.strictEqual(res.statusCode, 200); 841cb0ef41Sopenharmony_ci assert.strictEqual(res.headers.foo, '1'); 851cb0ef41Sopenharmony_ci assert.strictEqual(res.headers.bar, '2'); 861cb0ef41Sopenharmony_ci res.resume().on('end', common.mustCall(() => { 871cb0ef41Sopenharmony_ci server.close(); 881cb0ef41Sopenharmony_ci })); 891cb0ef41Sopenharmony_ci }); 901cb0ef41Sopenharmony_ci })); 911cb0ef41Sopenharmony_ci} 921cb0ef41Sopenharmony_ci 931cb0ef41Sopenharmony_ci{ 941cb0ef41Sopenharmony_ci const server = http.createServer({ requireHostHeader: false }, common.mustCall((req, res) => { 951cb0ef41Sopenharmony_ci const headers = new globalThis.Headers({ foo: '1', bar: '2' }); 961cb0ef41Sopenharmony_ci res.setHeaders(headers); 971cb0ef41Sopenharmony_ci res.writeHead(200, ['foo', '3']); 981cb0ef41Sopenharmony_ci res.end(); 991cb0ef41Sopenharmony_ci })); 1001cb0ef41Sopenharmony_ci 1011cb0ef41Sopenharmony_ci server.listen(0, common.mustCall(() => { 1021cb0ef41Sopenharmony_ci http.get({ port: server.address().port }, (res) => { 1031cb0ef41Sopenharmony_ci assert.strictEqual(res.statusCode, 200); 1041cb0ef41Sopenharmony_ci assert.strictEqual(res.headers.foo, '3'); // Override by writeHead 1051cb0ef41Sopenharmony_ci assert.strictEqual(res.headers.bar, '2'); 1061cb0ef41Sopenharmony_ci res.resume().on('end', common.mustCall(() => { 1071cb0ef41Sopenharmony_ci server.close(); 1081cb0ef41Sopenharmony_ci })); 1091cb0ef41Sopenharmony_ci }); 1101cb0ef41Sopenharmony_ci })); 1111cb0ef41Sopenharmony_ci} 1121cb0ef41Sopenharmony_ci 1131cb0ef41Sopenharmony_ci{ 1141cb0ef41Sopenharmony_ci const server = http.createServer({ requireHostHeader: false }, common.mustCall((req, res) => { 1151cb0ef41Sopenharmony_ci const headers = new Map([['foo', '1'], ['bar', '2']]); 1161cb0ef41Sopenharmony_ci res.setHeaders(headers); 1171cb0ef41Sopenharmony_ci res.writeHead(200); 1181cb0ef41Sopenharmony_ci res.end(); 1191cb0ef41Sopenharmony_ci })); 1201cb0ef41Sopenharmony_ci 1211cb0ef41Sopenharmony_ci server.listen(0, common.mustCall(() => { 1221cb0ef41Sopenharmony_ci http.get({ port: server.address().port }, (res) => { 1231cb0ef41Sopenharmony_ci assert.strictEqual(res.statusCode, 200); 1241cb0ef41Sopenharmony_ci assert.strictEqual(res.headers.foo, '1'); 1251cb0ef41Sopenharmony_ci assert.strictEqual(res.headers.bar, '2'); 1261cb0ef41Sopenharmony_ci res.resume().on('end', common.mustCall(() => { 1271cb0ef41Sopenharmony_ci server.close(); 1281cb0ef41Sopenharmony_ci })); 1291cb0ef41Sopenharmony_ci }); 1301cb0ef41Sopenharmony_ci })); 1311cb0ef41Sopenharmony_ci} 132