-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Closed
Labels
bugBug or defectBug or defect
Description
Runtime
node.js
Runtime version
22.17.1
Module version
21.4.3
Last module version without issue
No response
Used with
No response
Any other relevant information
No response
What are you trying to achieve or the steps to reproduce?
- I created a Hapi server with
host: '::1'to force listen to IPv6. - I added a preResponse listener that simply prints
request.url.
Here's a minimal reproduction setup:
const fs = require('fs');
const https = require('https');
const hapi = require('@hapi/hapi');
// created using: openssl req -newkey rsa:2048 -nodes -keyout key.pem -x509 -days 365 -out cert.pem
const tls = {
key: fs.readFileSync('key.pem'),
cert: fs.readFileSync('cert.pem'),
};
const server = hapi.server({ host: '::1', port: 10001, tls });
server.route({
method: 'GET',
path: '/foo',
handler: (req, h) => h.response('Hello world!').code(200),
});
server.ext('onPreResponse', (request) => {
console.log('URL is ', request.url);
});
server.start().then(() => {
const host = '::1';
const port = 10001;
const path = '/foo';
// prevent failure due to self-signed certificates
const agent = new https.Agent({ rejectUnauthorized: false });
const req = https.request({ host, port, agent, path }, (res) => {
console.log('statusCode:', res.statusCode);
console.log('headers:', res.headers);
res.on('data', (d) => {
process.stdout.write(d);
process.exit(0);
});
});
req.on('error', (e) => {
console.error(e);
process.exit(1);
});
req.end();
});What was the result you got?
- This line fails with
TypeError: Failed to parse URL from [object Object]
at node:internal/deps/undici/undici:13510:13
at process.processTicksAndRejections (node:internal/process/task_queues:105:5) {
[cause]: TypeError: Invalid URL
Illustrative example of correct vs incorrect URL
const Url = require('url');
const works = '[::1]';
const fails = '::1';
this._url = new Url.URL(`https://${works}:8080/app/main`);
this._url = new Url.URL(`https://${fails}:8080/app/main`);What result did you expect?
I would expect to be able to print the URL without any issues
Metadata
Metadata
Assignees
Labels
bugBug or defectBug or defect