11cb0ef41Sopenharmony_ci'use strict'; 21cb0ef41Sopenharmony_ci 31cb0ef41Sopenharmony_ciconst common = require('../common'); 41cb0ef41Sopenharmony_ciconst assert = require('node:assert'); 51cb0ef41Sopenharmony_ciconst http = require('node:http'); 61cb0ef41Sopenharmony_ci 71cb0ef41Sopenharmony_ciconst headers = { foo: 'Bar' }; 81cb0ef41Sopenharmony_ciconst server = http.createServer(common.mustCall((req, res) => { 91cb0ef41Sopenharmony_ci assert.strictEqual(req.url, '/ping?q=term'); 101cb0ef41Sopenharmony_ci assert.strictEqual(req.headers?.foo, headers.foo); 111cb0ef41Sopenharmony_ci req.resume(); 121cb0ef41Sopenharmony_ci req.on('end', () => { 131cb0ef41Sopenharmony_ci res.writeHead(200); 141cb0ef41Sopenharmony_ci res.end('pong'); 151cb0ef41Sopenharmony_ci }); 161cb0ef41Sopenharmony_ci})); 171cb0ef41Sopenharmony_ci 181cb0ef41Sopenharmony_ciserver.listen(0, common.localhostIPv4, () => { 191cb0ef41Sopenharmony_ci const { address, port } = server.address(); 201cb0ef41Sopenharmony_ci const url = new URL(`http://${address}:${port}/ping?q=term`); 211cb0ef41Sopenharmony_ci url.headers = headers; 221cb0ef41Sopenharmony_ci const clientReq = http.request(url); 231cb0ef41Sopenharmony_ci clientReq.on('close', common.mustCall(() => { 241cb0ef41Sopenharmony_ci server.close(); 251cb0ef41Sopenharmony_ci })); 261cb0ef41Sopenharmony_ci clientReq.end(); 271cb0ef41Sopenharmony_ci}); 28