-
Notifications
You must be signed in to change notification settings - Fork 6k
Use proxy-agent to support $HTTP_PROXY #2400
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
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
67470f0
node: coder-cloud -> coder_cloud
nhooyr cee88ad
update.ts: Fix response memory leak
nhooyr 691d44d
Use proxy-agent to support $HTTP_PROXY
nhooyr a72c642
proxy_agent.ts: Document that no other code passes in explicit agent
nhooyr 9e44dd8
vscode: Document argument to extensionHostProcess
nhooyr ca3af6d
vscode/coder.js: Remove unnecessary vs/css and vs/nls args
nhooyr 8a3471c
vscode: Fix @coder/logger version
nhooyr c15b526
vscode: Fix exthost logging
nhooyr a021bf5
Fix CI
nhooyr 58bbf25
proxy_agent.ts: Document why there is no $HTTPS_PROXY support
nhooyr 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
Large diffs are not rendered by default.
Oops, something went wrong.
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
File renamed without changes.
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
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,62 @@ | ||
import { logger } from "@coder/logger" | ||
import * as http from "http" | ||
import * as proxyagent from "proxy-agent" | ||
|
||
/** | ||
* This file does not have anything to do with the code-server proxy. | ||
* It's for $HTTP_PROXY support! | ||
* - https://github.com/cdr/code-server/issues/124 | ||
* - https://www.npmjs.com/package/proxy-agent | ||
* | ||
* This file exists in two locations: | ||
* - src/node/proxy_agent.ts | ||
* - lib/vscode/src/vs/base/node/proxy_agent.ts | ||
* The second is a symlink to the first. | ||
*/ | ||
|
||
/** | ||
* monkeyPatch patches the node HTTP/HTTPS library to route all requests through our | ||
* custom agent from the proxyAgent package. | ||
*/ | ||
export function monkeyPatch(vscode: boolean): void { | ||
// We do not support HTTPS_PROXY here to avoid confusion. proxy-agent will automatically | ||
// use the correct protocol to connect to the proxy depending on the requested URL. | ||
// | ||
// We could implement support ourselves to allow people to configure the proxy used for | ||
// HTTPS vs HTTP but there doesn't seem to be much value in that. | ||
// | ||
// At least of right now, it'd just be plain confusing to support HTTPS_PROXY when proxy-agent | ||
// will still use HTTP to hit it for HTTP requests. | ||
const proxyURL = process.env.HTTP_PROXY || process.env.http_proxy | ||
if (!proxyURL) { | ||
return | ||
} | ||
|
||
logger.debug(`using $HTTP_PROXY ${process.env.HTTP_PROXY}`) | ||
|
||
let pa: http.Agent | ||
// The reasoning for this split is that VS Code's build process does not have | ||
// esModuleInterop enabled but the code-server one does. As a result depending on where | ||
// we execute, we either have a default attribute or we don't. | ||
// | ||
// I can't enable esModuleInterop in VS Code's build process as it breaks and spits out | ||
// a huge number of errors. | ||
if (vscode) { | ||
pa = new (proxyagent as any)(process.env.HTTP_PROXY) | ||
} else { | ||
pa = new (proxyagent as any).default(process.env.HTTP_PROXY) | ||
} | ||
|
||
/** | ||
* None of our code ever passes in a explicit agent to the http modules but VS Code's | ||
* does sometimes but only when a user sets the http.proxy configuration. | ||
* See https://code.visualstudio.com/docs/setup/network#_legacy-proxy-server-support | ||
* | ||
* Even if they do, it's probably the same proxy so we should be fine! And those are | ||
* deprecated anyway. | ||
*/ | ||
const http = require("http") | ||
const https = require("https") | ||
http.globalAgent = pa | ||
https.globalAgent = pa | ||
} |
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
Oops, something went wrong.
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.