11cb0ef41Sopenharmony_ci'use strict';
21cb0ef41Sopenharmony_ciconst common = require('../common');
31cb0ef41Sopenharmony_ciconst assert = require('node:assert');
41cb0ef41Sopenharmony_ciconst http = require('node:http');
51cb0ef41Sopenharmony_ciconst debug = require('node:util').debuglog('test');
61cb0ef41Sopenharmony_ci
71cb0ef41Sopenharmony_ciconst testResBody = 'response content\n';
81cb0ef41Sopenharmony_ci
91cb0ef41Sopenharmony_ci{
101cb0ef41Sopenharmony_ci  const server = http.createServer(common.mustCall((req, res) => {
111cb0ef41Sopenharmony_ci    debug('Server sending early hints...');
121cb0ef41Sopenharmony_ci    assert.throws(() => {
131cb0ef41Sopenharmony_ci      res.writeEarlyHints('bad argument type');
141cb0ef41Sopenharmony_ci    }, (err) => err.code === 'ERR_INVALID_ARG_TYPE');
151cb0ef41Sopenharmony_ci
161cb0ef41Sopenharmony_ci    assert.throws(() => {
171cb0ef41Sopenharmony_ci      res.writeEarlyHints({
181cb0ef41Sopenharmony_ci        link: '</>; '
191cb0ef41Sopenharmony_ci      });
201cb0ef41Sopenharmony_ci    }, (err) => err.code === 'ERR_INVALID_ARG_VALUE');
211cb0ef41Sopenharmony_ci
221cb0ef41Sopenharmony_ci    assert.throws(() => {
231cb0ef41Sopenharmony_ci      res.writeEarlyHints({
241cb0ef41Sopenharmony_ci        link: 'rel=preload; </scripts.js>'
251cb0ef41Sopenharmony_ci      });
261cb0ef41Sopenharmony_ci    }, (err) => err.code === 'ERR_INVALID_ARG_VALUE');
271cb0ef41Sopenharmony_ci
281cb0ef41Sopenharmony_ci    assert.throws(() => {
291cb0ef41Sopenharmony_ci      res.writeEarlyHints({
301cb0ef41Sopenharmony_ci        link: 'invalid string'
311cb0ef41Sopenharmony_ci      });
321cb0ef41Sopenharmony_ci    }, (err) => err.code === 'ERR_INVALID_ARG_VALUE');
331cb0ef41Sopenharmony_ci
341cb0ef41Sopenharmony_ci    debug('Server sending full response...');
351cb0ef41Sopenharmony_ci    res.end(testResBody);
361cb0ef41Sopenharmony_ci    server.close();
371cb0ef41Sopenharmony_ci  }));
381cb0ef41Sopenharmony_ci
391cb0ef41Sopenharmony_ci  server.listen(0, common.mustCall(() => {
401cb0ef41Sopenharmony_ci    const req = http.request({
411cb0ef41Sopenharmony_ci      port: server.address().port, path: '/'
421cb0ef41Sopenharmony_ci    });
431cb0ef41Sopenharmony_ci
441cb0ef41Sopenharmony_ci    req.end();
451cb0ef41Sopenharmony_ci    debug('Client sending request...');
461cb0ef41Sopenharmony_ci
471cb0ef41Sopenharmony_ci    req.on('information', common.mustNotCall());
481cb0ef41Sopenharmony_ci  }));
491cb0ef41Sopenharmony_ci}
50