Skip to content

bugfix: use upstream proxy - #1128

Closed
BernhardRode wants to merge 1 commit into
http-party:masterfrom
BernhardRode:feature/handle-to-proxy
Closed

BernhardRode wants to merge 1 commit into
http-party:masterfrom
BernhardRode:feature/handle-to-proxy

Conversation

@BernhardRode

Copy link
Copy Markdown

Handle toProxy option properly and get proxy settings from environment.

There is an option toProxy (true/false) for http-proxy. But it is never used afaiks.
This fix checks the option and uses the http/https proxy set in the environment variables.

Usage:

{
  "/api": {
    "target": "http://upstreamserver.net",
    "toProxy": true
  }
}

Sorry, for I had no time for unit tests (just needed a local hotfix ;) )... If you like the solution I could into this PR in more detail during the weekend.

Handle toProxy option properly and get proxy settings from environment.
@assiomatica

Copy link
Copy Markdown

Hi,

I have tested your patch, as is it's not working, below the correct code:

`if (options.toProxy) {
var upstreamProxyServer;
if (typeof options.toProxy === 'boolean') {
upstreamProxyServer = url.parse(
isSSL.test(options[forward || 'target'].protocol) ? process.env['https_proxy'] || '' : process.env['http_proxy'] || ''
);
} else {
upstreamProxyServer = url.parse(options.toProxy);
}

if (upstreamProxyServer) {
  outgoing.path = options[forward || 'target'].protocol + '//' + outgoing.host + outgoing.path;
  outgoing.host = upstreamProxyServer.host;
  outgoing.hostname = upstreamProxyServer.hostname;
  outgoing.port = upstreamProxyServer.port;
}

}
`

@pi0 pi0 mentioned this pull request Mar 25, 2026
21 of 58 tasks
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