Skip to content

Commit

Permalink
feat: auto setup proxy for http requests (#69)
Browse files Browse the repository at this point in the history
* feat: auto setup proxy for http requests

* Adds dependencies

* Triggers CI again

Co-authored-by: Maël Nison <nison.mael@gmail.com>
  • Loading branch information
Djaler and arcanis committed Apr 7, 2022
1 parent 9d4bb08 commit 876ce02
Show file tree
Hide file tree
Showing 38 changed files with 679 additions and 8 deletions.
347 changes: 347 additions & 0 deletions .pnp.cjs

Large diffs are not rendered by default.

Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,8 @@ This command will retrieve the given package manager from the specified archive

- `COREPACK_ROOT` has no functional impact on Corepack itself; it's automatically being set in your environment by Corepack when it shells out to the underlying package managers, so that they can feature-detect its presence (useful for commands like `yarn init`).

- `HTTP_PROXY`, `HTTPS_PROXY`, and `NO_PROXY` are supported through [`node-proxy-agent`](https://github.com/TooTallNate/node-proxy-agent).

## Contributing

If you want to build corepack yourself, you can build the project like this:
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
"eslint-plugin-arca": "^0.9.5",
"jest": "^26.0.0",
"nock": "^13.0.4",
"proxy-agent": "^4.0.1",
"rimraf": "^3.0.2",
"semver": "^7.1.3",
"supports-color": "^7.1.0",
Expand Down
6 changes: 5 additions & 1 deletion sources/httpUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,12 @@ export async function fetchUrlStream(url: string, options: RequestOptions = {})

const {default: https} = await import(`https`);

const {default: ProxyAgent} = await import(`proxy-agent`);

const proxyAgent = new ProxyAgent();

return new Promise<IncomingMessage>((resolve, reject) => {
const request = https.get(url, options, response => {
const request = https.get(url, {...options, agent: proxyAgent}, response => {
const statusCode = response.statusCode ?? 500;
if (!(statusCode >= 200 && statusCode < 300))
return reject(new Error(`Server answered with HTTP ${statusCode}`));
Expand Down
Loading

0 comments on commit 876ce02

Please sign in to comment.