Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[fix] request does not support IPv6 addresses #1828

Open
3 tasks done
davidje13 opened this issue Feb 12, 2025 · 1 comment
Open
3 tasks done

[fix] request does not support IPv6 addresses #1828

davidje13 opened this issue Feb 12, 2025 · 1 comment
Labels

Comments

@davidje13
Copy link

Describe the bug

Node.js version: 23.4.0

OS version: Ubuntu 24.10 / Mac OS 15.3

Description:

This line tries to set the host option in a call to http.request to the hostname from the requested URL, but URL.hostname includes [] wrapping, and http.request's host fails when this is provided:

new URL('http://[::1]:8080').hostname // [::1]

http.request({ port: 8080, host: '[::1]' }) // fails

http.request({ port: 8080, host: '::1' }) // fine

I would list this as a feature request rather than a bug, but it's clear from nearby code that IPv6 is intended to be supported already.

Code to reproduce

This was originally reported to me here davidje13/superwstest#18 and narrowed down to when supertest is invoked with an IPv6 URL. A minimal reproduction using only superagent:

import { createServer } from 'node:http';
import superagent from 'superagent';

const server = createServer((req, res) => { res.statusCode=200; res.end('hi'); });
server.listen(8080, '::1', async () => {
  await superagent.get('http://[::1]:8080');
});

Actual behavior

Error: getaddrinfo ENOTFOUND [::1]
    at GetAddrInfoReqWrap.onlookupall [as oncomplete] (node:dns:120:26) {
  errno: -3008,
  code: 'ENOTFOUND',
  syscall: 'getaddrinfo',
  hostname: '[::1]',
  response: undefined
}

Expected behavior

Successful request to server

Checklist

  • I have searched through GitHub issues for similar issues.
  • I have completely read through the README and documentation.
  • I have tested my code with the latest version of Node.js and this package and confirmed it is still not working.
@titanism
Copy link
Collaborator

PR welcome

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants