Skip to content

bugfix: use upstream proxy#1128

Open
BernhardRode wants to merge 1 commit intohttp-party:masterfrom
BernhardRode:feature/handle-to-proxy
Open

bugfix: use upstream proxy#1128
BernhardRode wants to merge 1 commit intohttp-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;
}

}
`

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