-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #3432 from NomicFoundation/improve-proxy-support
Improve proxy support
- Loading branch information
Showing
12 changed files
with
120 additions
and
158 deletions.
There are no files selected for viewing
This file contains 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,5 @@ | ||
--- | ||
"@nomiclabs/hardhat-etherscan": patch | ||
--- | ||
|
||
Added support for the `http_proxy` environment variable. When this variable is set, `hardhat-etherscan` will use the given proxy to send the verification requests. |
This file contains 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,11 @@ | ||
--- | ||
"hardhat": patch | ||
--- | ||
|
||
Added support for the `http_proxy` environment variable. When this variable is set, Hardhat will send its requests through the given proxy for things like JSON-RPC requests, mainnet forking and downloading compilers. | ||
|
||
We also removed support for the `HTTP_PROXY` and `HTTPS_PROXY` environment variables, since `http_proxy` is the most commonly used environment variable for this kind of thing. Those variables could only be used for downloading compilers. | ||
|
||
Finally, we also added support for `no_proxy`, which accepts a comma separated list of hosts or `"*"`. Any host included in this list will not be proxied. | ||
|
||
Note that requests to `"localhost"` or `"127.0.0.1"` are never proxied. |
This file contains 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 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 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 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 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,18 @@ | ||
export function shouldUseProxy(url: string): boolean { | ||
const { hostname } = new URL(url); | ||
const noProxy = process.env.NO_PROXY; | ||
|
||
if (hostname === "localhost" || hostname === "127.0.0.1" || noProxy === "*") { | ||
return false; | ||
} | ||
|
||
if (noProxy !== undefined && noProxy !== "") { | ||
const noProxyList = noProxy.split(","); | ||
|
||
if (noProxyList.includes(hostname)) { | ||
return false; | ||
} | ||
} | ||
|
||
return true; | ||
} |
This file contains 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 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 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 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,38 @@ | ||
import type * as Undici from "undici"; | ||
|
||
function getDispatcher(): Undici.Dispatcher { | ||
const { ProxyAgent, getGlobalDispatcher } = | ||
require("undici") as typeof Undici; | ||
if (process.env.http_proxy !== undefined) { | ||
return new ProxyAgent(process.env.http_proxy); | ||
} | ||
|
||
return getGlobalDispatcher(); | ||
} | ||
|
||
export async function sendGetRequest( | ||
url: URL | ||
): Promise<Undici.Dispatcher.ResponseData> { | ||
const { request } = await import("undici"); | ||
const dispatcher = getDispatcher(); | ||
|
||
return request(url, { | ||
dispatcher, | ||
method: "GET", | ||
}); | ||
} | ||
|
||
export async function sendPostRequest( | ||
url: URL, | ||
body: string | ||
): Promise<Undici.Dispatcher.ResponseData> { | ||
const { request } = await import("undici"); | ||
const dispatcher = getDispatcher(); | ||
|
||
return request(url, { | ||
dispatcher, | ||
method: "POST", | ||
headers: { "Content-Type": "application/x-www-form-urlencoded" }, | ||
body, | ||
}); | ||
} |
Oops, something went wrong.