-
Notifications
You must be signed in to change notification settings - Fork 9
support for http, https and socks proxy #140
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
graju256
merged 10 commits into
Layer7-Community:feature/F154151_socks_proxy
from
karunakara-reddymaram-brt:feature/F154151_socks_proxy_basecode
Mar 11, 2026
Merged
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
fc2ab86
support for http, https and socks proxy
karunakara-reddymaram-brt 9bf3129
addressing review comments
karunakara-reddymaram-brt 29456e3
addressing review comments
karunakara-reddymaram-brt 667c908
Update graphman.configuration with single proxy extention
karunakara-reddymaram-brt 014780f
Merge remote-tracking branch 'refs/remotes/origin/feature/F154151_soc…
karunakara-reddymaram-brt cac9fd2
addressing review comments
karunakara-reddymaram-brt 7adc76d
addressing review comments
karunakara-reddymaram-brt d869d71
addressing review comments
karunakara-reddymaram-brt a36522b
addressing review comments
karunakara-reddymaram-brt ee1d411
addressing review comments
karunakara-reddymaram-brt File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -31,7 +31,8 @@ | |
| "post-export", | ||
| "pre-import", | ||
| "post-revise", | ||
| "post-renew" | ||
| "post-renew", | ||
| "http-proxy" | ||
| ] | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,102 @@ | ||
| // Copyright (c) 2026 Broadcom Inc. and its subsidiaries. All Rights Reserved. | ||
| module.exports = { | ||
| /** | ||
| * * Extension to provide HTTP proxy agent | ||
| * * @param input http proxy configuration | ||
| * * @param input.address proxy server url | ||
| * * @param input.credentialRef proxy credential reference | ||
| * * @param input.options extra proxy agent options | ||
| * * @param context has the context of current operation details | ||
| * * @return proxy agent instance | ||
| */ | ||
| apply: function (input, context) { | ||
|
|
||
| if(input.agentType === "socks") { | ||
| return createSocksProxyAgent(input, context); | ||
| } else { | ||
| return createHttpProxyAgent(input, context); | ||
| } | ||
| } | ||
| } | ||
|
|
||
| function createSocksProxyAgent(input, context) { | ||
| let agent = null; | ||
| const proxyConfig = createProxyConfig(input); | ||
|
|
||
| try { | ||
| const { SocksProxyAgent } = require("socks-proxy-agent"); | ||
| agent = new SocksProxyAgent(proxyConfig.url || new URL(input.address), proxyConfig); | ||
| } catch (e) { | ||
| throw "failed to configure socks proxy agent" + e.message; | ||
| } | ||
| return agent | ||
| } | ||
|
|
||
| function createHttpProxyAgent(input, context) { | ||
| let agent = null; | ||
| const isHttps = context.gateway["address"].startsWith('https://'); | ||
| const proxyConfig = createProxyConfig(input); | ||
| const proxyUrlLower = input.address.toLowerCase(); | ||
| const isProxyHttps = proxyUrlLower.startsWith('https://'); | ||
|
|
||
| if (isProxyHttps) { | ||
| // If proxy URL uses https://, ensure TLS options are configured if needed | ||
| if (!proxyConfig.tls) { | ||
| proxyConfig.tls = {}; | ||
| } | ||
| // If rejectUnauthorized is not explicitly set for proxy TLS, default to false for compatibility | ||
| if (proxyConfig.tls.rejectUnauthorized === undefined) { | ||
| proxyConfig.tls.rejectUnauthorized = false; | ||
| } | ||
| } | ||
|
Comment on lines
+42
to
+51
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not sure about this section. Please check it whether it is really affecting the client connection behavior. |
||
|
|
||
| try { | ||
| // Use https-proxy-agent for HTTPS targets, http-proxy-agent for HTTP targets | ||
| // Note: The agent type is based on TARGET protocol, not proxy URL protocol | ||
|
|
||
| if (isHttps) { | ||
| const { HttpsProxyAgent } = require("https-proxy-agent") | ||
| agent = new HttpsProxyAgent(input.address, proxyConfig); | ||
| } else { | ||
| const { HttpProxyAgent } = require("http-proxy-agent") | ||
| agent = new HttpProxyAgent(input.address, proxyConfig); | ||
| } | ||
|
|
||
| } catch (e) { | ||
| throw "failed to configure http proxy agent " + e.message; | ||
| } | ||
|
|
||
| return agent; | ||
| } | ||
|
|
||
| function createProxyConfig(obj) { | ||
| const proxy = {}; | ||
| const cred = obj.credentialRef; | ||
| let auth; | ||
|
|
||
| if (cred) { | ||
| if (obj.agentType === "socks") { | ||
| const url = new URL(obj.address); | ||
| url.username = cred.username; | ||
| url.password = cred.password; | ||
|
|
||
| proxy.url = url; | ||
| } else { | ||
| auth = `Basic ${Buffer.from(`${cred.username}:${cred.password}`).toString('base64')}`; | ||
| } | ||
| } | ||
|
|
||
| Object.keys(obj.options).forEach(key => { | ||
| proxy[key] = obj.options[key]; | ||
| }); | ||
|
|
||
| if (!proxy.headers) { | ||
| proxy.headers = {}; | ||
| } | ||
|
|
||
| if (auth) { | ||
| proxy.headers["Proxy-Authorization"] = auth; | ||
| } | ||
|
|
||
| return proxy; | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.