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

PAC proxy with *_PROXY env vars is broken #219

Closed
Drarig29 opened this issue Jul 13, 2023 · 2 comments · Fixed by #220
Closed

PAC proxy with *_PROXY env vars is broken #219

Drarig29 opened this issue Jul 13, 2023 · 2 comments · Fixed by #220

Comments

@Drarig29
Copy link

With proxy-agent@5.0.0, the following code worked (example taken from here):

// index.mjs

import * as http from 'http'
import ProxyAgent from 'proxy-agent'

// The correct proxy `Agent` implementation to use will be determined
// via the `http_proxy` / `https_proxy` / `no_proxy` / etc. env vars
const agent = new ProxyAgent()

// The rest works just like any other normal HTTP request
http.get('http://jsonip.com', {agent}, (res) => {
  console.log(res.statusCode, res.headers)
  res.pipe(process.stdout)
})

Test command line (this uses a PAC file which only returns "DIRECT"):

DEBUG=proxy-agent,pac-proxy-agent HTTP_PROXY=pac+https://gist.githubusercontent.com/Drarig29/d6dcf7f2995921e063006afb01b776db/raw/84fed7334300698e6e7390a4928de592d5666e99/noop-proxy.pac node index.mjs

After upgrading to proxy-agent@6.2.1 (and doing this little change:)

- import ProxyAgent from 'proxy-agent'
+ import {ProxyAgent} from 'proxy-agent'

Then it fails with this:

  proxy-agent Creating new ProxyAgent instance: undefined +0ms
  proxy-agent Request URL: 'http://jsonip.com/' +3ms
  proxy-agent Proxy URL: 'pac+https://gist.githubusercontent.com/Drarig29/d6dcf7f2995921e063006afb01b776db/raw/84fed7334300698e6e7390a4928de592d5666e99/noop-proxy.pac' +0ms

node:events:491
      throw er; // Unhandled 'error' event
      ^

Error: Unsupported protocol for proxy URL: pac+https://gist.githubusercontent.com/Drarig29/d6dcf7f2995921e063006afb01b776db/raw/84fed7334300698e6e7390a4928de592d5666e99/noop-proxy.pac
    at ProxyAgent.connect (/Users/corentin.girard/playground/mcve-bug-pac-proxy-agent/node_modules/proxy-agent/dist/index.js:113:23)
    at /Users/corentin.girard/playground/mcve-bug-pac-proxy-agent/node_modules/agent-base/dist/index.js:73:30
Emitted 'error' event on ClientRequest instance at:
    at _destroy (node:_http_client:874:13)
    at onSocketNT (node:_http_client:891:5)
    at processTicksAndRejections (node:internal/process/task_queues:84:21)

I think that's because isValidProtocol()

if (!isValidProtocol(proxyProto)) {
throw new Error(`Unsupported protocol for proxy URL: ${proxy}`);
}

uses those protocols:

static readonly protocols: `pac-${Protocols}`[] = [
'pac-data',
'pac-file',
'pac-ftp',
'pac-http',
'pac-https',
];

@TooTallNate
Copy link
Owner

Whoops, ya, good catch.

@TooTallNate
Copy link
Owner

Fixed in proxy-agent v6.2.2.

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 a pull request may close this issue.

2 participants