Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion packages/socks-proxy-agent/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@ const setServernameFromNonIpHost = <
function parseSocksURL(url: URL): { lookup: boolean; proxy: SocksProxy } {
let lookup = false;
let type: SocksProxy['type'] = 5;
const host = url.hostname;
// Trim off the brackets from IPv6 addresses
const host = url.hostname.replace(/^\[|\]$/g, '');

// From RFC 1928, Section 3: https://tools.ietf.org/html/rfc1928#section-3
// "The SOCKS service is conventionally located on TCP port 1080"
Expand Down
5 changes: 5 additions & 0 deletions packages/socks-proxy-agent/test/test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,11 @@ describe('SocksProxyAgent', () => {
assert.equal(socksServerUrl.hostname, agent.proxy.host);
assert.equal(+socksServerUrl.port, agent.proxy.port);
});
it('should trim brackets from an IPv6 literal proxy host', () => {
const agent = new SocksProxyAgent('socks5h://[::1]:1080');
assert.equal(agent.proxy.host, '::1');
assert.equal(agent.proxy.port, 1080);
});
it('should respect `timeout` option during connection to socks server', async () => {
const agent = new SocksProxyAgent(socksServerUrl, { timeout: 1 });

Expand Down