MathKimRobin
MathKimRobin

Reputation: 1440

node-fetch with ipv6 proxy

Do you know any way to use node-fetch (or similar package), with an ipv6 proxy ? I'm stuck on this "small" point.

I tried to

const fetch = require('node-fetch');
const HttpsProxyAgent = require('https-proxy-agent');

class Something {
  async init (url) {
    return fetch(url, {agent: new HttpsProxyAgent('https://2a01:cb00:8612:c000:86d:5188:7abc:4c2f')})
      .then(res => res.text())
    }
}

But was not working (surprise...)

Got:

failed, reason: getaddrinfo ENOTFOUND 2a01

I'm sure that I'm making something stupid, but i don't understand what i can do or not with ipv6...

Upvotes: 2

Views: 2511

Answers (1)

Ron Maupin
Ron Maupin

Reputation: 6452

You are incorrectly formatting the IPv6 address literal in your URL. You need to surround the IPv6 address with brackets ([ and ]):

https://[2a01:cb00:8612:c000:86d:5188:7abc:4c2f]

This is explained in RFC 2732, Format for Literal IPv6 Addresses in URL's:

2.Literal IPv6 Address Format in URL's Syntax

To use a literal IPv6 address in a URL, the literal address should be enclosed in "[" and "]" characters. For example the following literal IPv6 addresses:

  FEDC:BA98:7654:3210:FEDC:BA98:7654:3210
  1080:0:0:0:8:800:200C:4171
  3ffe:2a00:100:7031::1
  1080::8:800:200C:417A
  ::192.9.5.5
  ::FFFF:129.144.52.38
  2010:836B:4179::836B:4179

would be represented as in the following example URLs:

  http://[FEDC:BA98:7654:3210:FEDC:BA98:7654:3210]:80/index.html
  http://[1080:0:0:0:8:800:200C:417A]/index.html
  http://[3ffe:2a00:100:7031::1]
  http://[1080::8:800:200C:417A]/foo
  http://[::192.9.5.5]/ipng
  http://[::FFFF:129.144.52.38]:80/index.html
  http://[2010:836B:4179::836B:4179]

Upvotes: 2

Related Questions