11cb0ef41Sopenharmony_ci'use strict';
21cb0ef41Sopenharmony_ciconst common = require('../common');
31cb0ef41Sopenharmony_ciconst assert = require('assert');
41cb0ef41Sopenharmony_ciconst http = require('http');
51cb0ef41Sopenharmony_ci
61cb0ef41Sopenharmony_ci// Verify that ServerResponse.writeHead() works with arrays.
71cb0ef41Sopenharmony_ci
81cb0ef41Sopenharmony_ci{
91cb0ef41Sopenharmony_ci  const server = http.createServer(common.mustCall((req, res) => {
101cb0ef41Sopenharmony_ci    res.setHeader('test', '1');
111cb0ef41Sopenharmony_ci    res.writeHead(200, [ 'test', '2', 'test2', '2' ]);
121cb0ef41Sopenharmony_ci    res.end();
131cb0ef41Sopenharmony_ci  }));
141cb0ef41Sopenharmony_ci
151cb0ef41Sopenharmony_ci  server.listen(0, common.mustCall(() => {
161cb0ef41Sopenharmony_ci    http.get({ port: server.address().port }, common.mustCall((res) => {
171cb0ef41Sopenharmony_ci      assert.strictEqual(res.headers.test, '2');
181cb0ef41Sopenharmony_ci      assert.strictEqual(res.headers.test2, '2');
191cb0ef41Sopenharmony_ci      res.resume().on('end', common.mustCall(() => {
201cb0ef41Sopenharmony_ci        server.close();
211cb0ef41Sopenharmony_ci      }));
221cb0ef41Sopenharmony_ci    }));
231cb0ef41Sopenharmony_ci  }));
241cb0ef41Sopenharmony_ci}
251cb0ef41Sopenharmony_ci
261cb0ef41Sopenharmony_ci{
271cb0ef41Sopenharmony_ci  const server = http.createServer(common.mustCall((req, res) => {
281cb0ef41Sopenharmony_ci    res.writeHead(200, [ 'test', '1', 'test2', '2' ]);
291cb0ef41Sopenharmony_ci    res.end();
301cb0ef41Sopenharmony_ci  }));
311cb0ef41Sopenharmony_ci
321cb0ef41Sopenharmony_ci  server.listen(0, common.mustCall(() => {
331cb0ef41Sopenharmony_ci    http.get({ port: server.address().port }, common.mustCall((res) => {
341cb0ef41Sopenharmony_ci      assert.strictEqual(res.headers.test, '1');
351cb0ef41Sopenharmony_ci      assert.strictEqual(res.headers.test2, '2');
361cb0ef41Sopenharmony_ci      res.resume().on('end', common.mustCall(() => {
371cb0ef41Sopenharmony_ci        server.close();
381cb0ef41Sopenharmony_ci      }));
391cb0ef41Sopenharmony_ci    }));
401cb0ef41Sopenharmony_ci  }));
411cb0ef41Sopenharmony_ci}
421cb0ef41Sopenharmony_ci
431cb0ef41Sopenharmony_ci
441cb0ef41Sopenharmony_ci{
451cb0ef41Sopenharmony_ci  const server = http.createServer(common.mustCall((req, res) => {
461cb0ef41Sopenharmony_ci    try {
471cb0ef41Sopenharmony_ci      res.writeHead(200, [ 'test', '1', 'test2', '2', 'asd' ]);
481cb0ef41Sopenharmony_ci    } catch (err) {
491cb0ef41Sopenharmony_ci      assert.strictEqual(err.code, 'ERR_INVALID_ARG_VALUE');
501cb0ef41Sopenharmony_ci    }
511cb0ef41Sopenharmony_ci    res.end();
521cb0ef41Sopenharmony_ci  }));
531cb0ef41Sopenharmony_ci
541cb0ef41Sopenharmony_ci  server.listen(0, common.mustCall(() => {
551cb0ef41Sopenharmony_ci    http.get({ port: server.address().port }, common.mustCall((res) => {
561cb0ef41Sopenharmony_ci      res.resume().on('end', common.mustCall(() => {
571cb0ef41Sopenharmony_ci        server.close();
581cb0ef41Sopenharmony_ci      }));
591cb0ef41Sopenharmony_ci    }));
601cb0ef41Sopenharmony_ci  }));
611cb0ef41Sopenharmony_ci}
621cb0ef41Sopenharmony_ci
631cb0ef41Sopenharmony_ci{
641cb0ef41Sopenharmony_ci  const server = http.createServer(common.mustCall((req, res) => {
651cb0ef41Sopenharmony_ci    res.writeHead(200, undefined, [ 'foo', 'bar' ]);
661cb0ef41Sopenharmony_ci    res.end();
671cb0ef41Sopenharmony_ci  }));
681cb0ef41Sopenharmony_ci
691cb0ef41Sopenharmony_ci  server.listen(0, common.mustCall(() => {
701cb0ef41Sopenharmony_ci    http.get({ port: server.address().port }, common.mustCall((res) => {
711cb0ef41Sopenharmony_ci      assert.strictEqual(res.statusMessage, 'OK');
721cb0ef41Sopenharmony_ci      assert.strictEqual(res.statusCode, 200);
731cb0ef41Sopenharmony_ci      assert.strictEqual(res.headers.foo, 'bar');
741cb0ef41Sopenharmony_ci      res.resume().on('end', common.mustCall(() => {
751cb0ef41Sopenharmony_ci        server.close();
761cb0ef41Sopenharmony_ci      }));
771cb0ef41Sopenharmony_ci    }));
781cb0ef41Sopenharmony_ci  }));
791cb0ef41Sopenharmony_ci}
80