Skip to content

Commit

Permalink
Use non-compliant URL from 'url' for socks urls (#242)
Browse files Browse the repository at this point in the history
`new URL('socks://host:port')` gives different results in browser and
Node.js because `socks` is not among the "special schemes" specified by
WHATWG and thus the hostname is treated as an opaque value (without
parsing the port). Node.js implementation, however, parses the `port`.

Since `proxy-agent` can be used in Electron, unless `URL` is imported
directly from the Node's `url` module - it is going to use the Browser's
version of it which won't work with socks urls.
  • Loading branch information
indutny-signal committed Sep 4, 2023
1 parent e625d10 commit 1d39f6c
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 1 deletion.
7 changes: 7 additions & 0 deletions .changeset/eleven-bags-attend.md
@@ -0,0 +1,7 @@
---
'socks-proxy-agent': patch
'pac-proxy-agent': patch
'proxy-agent': patch
---

Fix Electron support by using Node.js native URL object
2 changes: 1 addition & 1 deletion packages/pac-proxy-agent/src/index.ts
Expand Up @@ -5,7 +5,7 @@ import * as crypto from 'crypto';
import { once } from 'events';
import createDebug from 'debug';
import { Readable } from 'stream';
import { format } from 'url';
import { format, URL } from 'url';
import { Agent, AgentConnectOpts, toBuffer } from 'agent-base';
import { HttpProxyAgent, HttpProxyAgentOptions } from 'http-proxy-agent';
import { HttpsProxyAgent, HttpsProxyAgentOptions } from 'https-proxy-agent';
Expand Down
1 change: 1 addition & 0 deletions packages/proxy-agent/src/index.ts
@@ -1,5 +1,6 @@
import * as http from 'http';
import * as https from 'https';
import { URL } from 'url';
import LRUCache from 'lru-cache';
import { Agent, AgentConnectOpts } from 'agent-base';
import createDebug from 'debug';
Expand Down
1 change: 1 addition & 0 deletions packages/socks-proxy-agent/src/index.ts
Expand Up @@ -5,6 +5,7 @@ import * as dns from 'dns';
import * as net from 'net';
import * as tls from 'tls';
import * as http from 'http';
import { URL } from 'url';

const debug = createDebug('socks-proxy-agent');

Expand Down

1 comment on commit 1d39f6c

@vercel
Copy link

@vercel vercel bot commented on 1d39f6c Sep 4, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.