Skip to content

Add the full PAC-style result to resolveProxyByURL - #128

Merged
Christof Marti (chrmarti) merged 4 commits into
mainfrom
chrmarti/resolve-proxy-result
Nov 4, 2026
Merged

Christof Marti (chrmarti) merged 4 commits into
mainfrom
chrmarti/resolve-proxy-result

Conversation

@chrmarti

@chrmarti Christof Marti (chrmarti) commented Nov 4, 2026 •

Copy link
Copy Markdown

resolveProxyByURL now also returns result: the full PAC-style resolver result, of which url and type describe only the first entry they recognize. For example, a PAC returning PROXY proxy1:8080; HTTPS proxy2:8443; DIRECT previously reached callers as http://proxy1:8080 alone.

This lets VS Code hand the complete list, including its fallback entries, to resolvers that accept PAC-style results, such as the Copilot runtime's proxy resolution callback used by the agent host, so the runtime can fail over to the next proxy.

  • result is the string the resolver chose: DIRECT for localhost and noProxy matches, the http.proxy setting or proxy environment variable, the system/PAC result, or the cached one. It is undefined when the system resolver returned nothing.
  • System results, which come from Electron's session.resolveProxy, pass through unchanged. A proxy from the http.proxy setting or an environment variable appears as Electron would return it, so consumers get one format:
    • PROXY, HTTPS, SOCKS5 or SOCKS (SOCKSv4, as Chromium names it in PAC results) with host:port.
    • The scheme's default port (80, 443 or 1080) when none is given.
    • No credentials, path, query or fragment. A malformed proxy becomes DIRECT, as Chromium drops malformed proxies.
  • url is unchanged and keeps any credentials for connecting through the proxy.
  • Additive, so existing callers are unaffected. Bumps the version to 0.46.0 with a changelog entry.

Tests: npm run compile and npm run test:unit pass (38 passing, 1 pending). The existing resolveProxyByURL tests now also check result. New tests cover:

  • a multi-entry system result, fresh and from the cache;
  • http.proxy values with credentials, default ports, a path, IPv6, SOCKS5, SOCKS4 and a malformed port;
  • an environment variable with credentials (including an unencoded @ in the password) and a trailing slash;
  • a system result whose entry has a userinfo, which passes through unchanged.

CI fix (separate commit): main's integration tests have failed since the mocha 12 update (#127) with ERR_REQUIRE_ESM, because mocha 12 needs Node ^20.19.0 || >=22.12.0 and the Docker test clients ran node:20.18.1. The test clients now run node:22.23.4. On Node 22 the test client's kerberos 2.0.1 doesn't compile (node-addon-api 4.3.0), so it moves to kerberos 2.2.2 (node-addon-api 6.1.0, same API). Verified locally with docker compose run --rm test-direct-client (34 passing, 1 pending) and test-proxy-client (39 passing).

resolveProxyByURL's url and type describe only the first entry of a resolver result, so callers that hand proxies on to another resolver, such as the Copilot runtime's resolveProxy callback, lose the fallback entries of a PAC result like 'PROXY proxy1:8080; PROXY proxy2:8080; DIRECT'. The new result field keeps them.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Like Electron's session.resolveProxy, whose results never include userinfo, the result now drops the credentials of a proxy from the http.proxy setting or an environment variable. Consumers that hand the result to other PAC-style resolvers then never pass credentials on. The url field keeps them for connecting through the proxy.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Only proxies from the http.proxy setting or an environment variable differ from what Electron's session.resolveProxy returns, so only these are rewritten, and system results pass through unchanged. They now appear as Chromium formats PAC results: PROXY, HTTPS, SOCKS5 or SOCKS (SOCKSv4) with host:port, the scheme's default port when none is given, and no credentials, path, query or fragment. A malformed one becomes DIRECT, as Chromium drops malformed proxies.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
mocha 12 requires Node ^20.19.0 || >=22.12.0 because its CLI loads an ES module with require(), so the integration tests failed on node:20.18.1 with ERR_REQUIRE_ESM. On Node 22, the test client's kerberos 2.0.1 does not compile (node-addon-api 4.3.0), so it moves to kerberos 2.2.2 (node-addon-api 6.1.0) with the same API.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@chrmarti
Christof Marti (chrmarti) marked this pull request as ready for review November 4, 2026 17:01
@chrmarti
Christof Marti (chrmarti) merged commit 3afbc6d into main Nov 4, 2026
6 checks passed
@chrmarti
Christof Marti (chrmarti) deleted the chrmarti/resolve-proxy-result branch November 4, 2026 17:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants