apify / proxy-chain

Node.js implementation of a proxy server (think Squid) with support for SSL, authentication and upstream proxy chaining.

Home Page:https://www.npmjs.com/package/proxy-chain

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Anonymize proxy throw hostname and port error when they are present

gutobortolozzo opened this issue · comments

Hi,

From version 0.4.8 and on I can't anonymize URLs like http://proxy:proxy321@my.domain.com, http://proxy:proxy321@my.domain.com:80 due to a change on /src/tools.js:parseUrl. This is happening because new URL(...) omit the default protocol port causing the anonymizeProxy(...) to throw an error Invalid "proxyUrl" option: the URL must contain both hostname and port..

> new URL('http://proxy:proxy321@my.domain.com:80')
URL {
  href: 'http://proxy:proxy321@my.domain.com/',
  origin: 'http://my.domain.com',
  protocol: 'http:',
  username: 'proxy',
  password: 'proxy321',
  host: 'my.domain.com',
  hostname: 'my.domain.com',
  port: '', // Empty port event when it is present
  pathname: '/',
  search: '',
  searchParams: URLSearchParams {},
  hash: ''
}

A possible fix here would be set the default http port on anonymizeProxy when parsedProxyUrl.protocol === 'http:' and port is empty. Thoughts?

Thank you.