Skip to content

Add HTTPS upstream proxy support with option to ignore proxy cert errors #577

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

Merged
merged 5 commits into from
Mar 28, 2025

Conversation

patrickkfkan
Copy link
Contributor

As title. E.g.:

const server = new Server({
  prepareRequestFunction: () => ({
    upstreamProxyUrl: 'https://user:pass@myproxy:8080',
    ignoreUpstreamProxyCertificate: true  // Useful for self-signed cert
  })
}).listen();

Anonymize:

anonymizeProxy({
  url: 'https://user:pass@myproxy:8080',
  ignoreProxyCertificate: true,
}).then((anonymizedURL) => {
  console.log(`Anonymized URL: ${anonymizedURL}`);
});

Create tunnel:

createTunnel(
  'https://user:pass@myproxy:8080',
  targetHost,
  { ignoreProxyCertificate: true }
).then((url) => {
  console.log('Tunnel endpoint:', url);
});

@jancurn jancurn requested a review from jirimoravcik March 18, 2025 18:18
@jirimoravcik
Copy link
Member

Hi @patrickkfkan,
thank you for your contribution!
the unit tests are sadly failing, would you be willing to take a look at that?

Thank you

@patrickkfkan
Copy link
Contributor Author

Hello! I missed the part where options can be undefined as the type definition for createTunnel() didn't reflect this. I've fixed this in the PR so unit tests should pass now. Could you please check again? Thanks!

@jirimoravcik
Copy link
Member

Hey, thanks for the fix. I noticed the lint is failing. Could you please rebase your PR on top of the current master branch? Thanks

@patrickkfkan
Copy link
Contributor Author

Done.

Copy link
Member

@jirimoravcik jirimoravcik left a comment

Choose a reason for hiding this comment

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

Hey, I'm almost ready to merge this PR, just a few small nits. Could you please take a look at them? Thanks

},
callback?: (error: Error | null, result?: string) => void,
): Promise<string> {
const parsedProxyUrl = new URL(proxyUrl);
if (parsedProxyUrl.protocol !== 'http:') {
throw new Error(`The proxy URL must have the "http" protocol (was "${proxyUrl}")`);
if (parsedProxyUrl.protocol !== 'http:' && parsedProxyUrl.protocol !== 'https:') {
Copy link
Member

Choose a reason for hiding this comment

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

Could you please do something with an array ['http:', 'https:'] and not in?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done.

@jirimoravcik jirimoravcik merged commit bad3172 into apify:master Mar 28, 2025
5 checks passed
@jirimoravcik
Copy link
Member

jirimoravcik commented Mar 28, 2025

This feature has landed in v2.5.8. @patrickkfkan thank you again for your contribution!

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