0
Fork 0
mirror of https://github.com/withastro/astro.git synced 2024-12-16 21:46:22 -05:00

Http proxy for fetch (#4676)

* Add HTTP Proxy Support to `fetch` Polyfill

Use `global-agent` to support HTTP_PROXY, HTTPS_PROXY, and NO_PROXY
environment variables.

* Add Changeset For HTTP Proxy Support in `fetch`
This commit is contained in:
Zicklag 2022-09-22 13:47:06 -05:00 committed by GitHub
parent 6ce8ae261f
commit 5e4c5252bd
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 92 additions and 2 deletions

View file

@ -0,0 +1,5 @@
---
'@astrojs/webapi': minor
---
Add HTTP Proxy Support to `fetch` Polyfill

View file

@ -50,6 +50,7 @@
"bugs": "https://github.com/withastro/astro/issues",
"homepage": "https://github.com/withastro/astro/tree/main/packages/webapi#readme",
"dependencies": {
"global-agent": "^3.0.0",
"node-fetch": "^3.2.5"
},
"devDependencies": {
@ -58,6 +59,7 @@
"@rollup/plugin-node-resolve": "^13.3.0",
"@rollup/plugin-typescript": "^8.3.2",
"@types/chai": "^4.3.1",
"@types/global-agent": "^2.1.1",
"@types/mocha": "^9.1.1",
"@types/node": "^14.18.21",
"@ungap/structured-clone": "^0.3.4",

View file

@ -178,7 +178,7 @@ async function build() {
inputOptions: {
input: 'src/polyfill.ts',
plugins: plugins,
external: ['node-fetch'],
external: ['node-fetch', 'global-agent'],
onwarn(warning, warn) {
if (warning.code !== 'UNRESOLVED_IMPORT') warn(warning)
},

View file

@ -2,6 +2,13 @@ import type { RequestInit } from 'node-fetch'
import { default as nodeFetch, Headers, Request, Response } from 'node-fetch'
import Stream from 'node:stream'
import * as _ from './utils'
import {
bootstrap as bootstrapGlobalAgent
} from 'global-agent';
bootstrapGlobalAgent({
environmentVariableNamespace: '',
});
export { Headers, Request, Response }

View file

@ -2969,6 +2969,7 @@ importers:
'@rollup/plugin-node-resolve': ^13.3.0
'@rollup/plugin-typescript': ^8.3.2
'@types/chai': ^4.3.1
'@types/global-agent': ^2.1.1
'@types/mocha': ^9.1.1
'@types/node': ^14.18.21
'@ungap/structured-clone': ^0.3.4
@ -2977,6 +2978,7 @@ importers:
event-target-shim: ^6.0.2
fetch-blob: ^3.1.5
formdata-polyfill: ^4.0.10
global-agent: ^3.0.0
magic-string: ^0.25.9
mocha: ^9.2.2
node-fetch: ^3.2.5
@ -2987,6 +2989,7 @@ importers:
urlpattern-polyfill: ^1.0.0-rc5
web-streams-polyfill: ^3.2.1
dependencies:
global-agent: 3.0.0
node-fetch: 3.2.10
devDependencies:
'@rollup/plugin-alias': 3.1.9_rollup@2.79.0
@ -2994,6 +2997,7 @@ importers:
'@rollup/plugin-node-resolve': 13.3.0_rollup@2.79.0
'@rollup/plugin-typescript': 8.5.0_ppxule2mhlgb6ds3e4gxjflaqy
'@types/chai': 4.3.3
'@types/global-agent': 2.1.1
'@types/mocha': 9.1.1
'@types/node': 14.18.29
'@ungap/structured-clone': 0.3.4
@ -9033,6 +9037,10 @@ packages:
'@types/node': 18.7.18
dev: true
/@types/global-agent/2.1.1:
resolution: {integrity: sha512-sVox8Phk1UKgP6LQPAdeRxfww6vHKt7Bf59dXzYLsQBUEMEn8S10a+ESp/yO0i4fJ3WS4+CIuz42hgJcuA+3mA==}
dev: true
/@types/hast/2.3.4:
resolution: {integrity: sha512-wLEm0QvaoawEDoTRwzTXp4b4jpwiJDvR5KMnFnVodm3scufTlBOWRD6N1OBf9TZMhjlNsSfcO5V+7AF4+Vy+9g==}
dependencies:
@ -10077,6 +10085,10 @@ packages:
/boolbase/1.0.0:
resolution: {integrity: sha512-JZOSA7Mo9sNGB8+UjSgzdLtokWAky1zbztM3WRLCbZ70/3cTANmQmOdR7y2g+J0e2WXywy1yS468tY+IruqEww==}
/boolean/3.2.0:
resolution: {integrity: sha512-d0II/GO9uf9lfUHH2BQsjxzRJZBdsjgsBiW4BvhWk/3qoKwQFjIDVN19PfX8F2D/r9PCMTtLWjYVCFrpeYUzsw==}
dev: false
/boxen/6.2.1:
resolution: {integrity: sha512-H4PEsJXfFI/Pt8sjDWbHlQPx4zL/bvSQjcilJmaulGt5mLDorHOHpmdXAJcBcmru7PhYSp/cDMWRko4ZUMFkSw==}
engines: {node: ^12.20.0 || ^14.13.1 || >=16.0.0}
@ -10830,6 +10842,10 @@ packages:
engines: {node: '>=8'}
dev: false
/detect-node/2.1.0:
resolution: {integrity: sha512-T0NIuQpnTvFDATNuHN5roPwSBG83rFsuO+MXXH9/3N1eFbn4wcPjttvjMLEPWJ0RGUYgQE7cGgS3tNxbqCGM7g==}
dev: false
/detective/5.2.1:
resolution: {integrity: sha512-v9XE1zRnz1wRtgurGu0Bs8uHKFSTdteYZNbIPFVhUZ39L/S79ppMpdmVOZAnoz1jfEFodc48n6MX483Xo3t1yw==}
engines: {node: '>=0.8.0'}
@ -11040,6 +11056,10 @@ packages:
is-date-object: 1.0.5
is-symbol: 1.0.4
/es6-error/4.1.1:
resolution: {integrity: sha512-Um/+FxMr9CISWh0bi5Zv0iOD+4cFh5qLeks1qhAopKVAJw3drgKbKySikp7wGhDL0HPeaja0P5ULZrxLkniUVg==}
dev: false
/es6-promise/3.3.1:
resolution: {integrity: sha512-SOp9Phqvqn7jtEUxPWdWfWoLmyt2VaJ6MpvP9Comy1MceMXqE6bxvaTu4iaxpYYPzhny28Lc+M87/c2cPK6lDg==}
dev: false
@ -11671,7 +11691,6 @@ packages:
/escape-string-regexp/4.0.0:
resolution: {integrity: sha512-TtpcNJ3XAzx3Gq8sWRzJaVajRs0uVxA2YAkdb1jm2YkPz4G6egUFAyA3n5vtEIZefPk5Wa4UXbKuS5fKkJWdgA==}
engines: {node: '>=10'}
dev: true
/escape-string-regexp/5.0.0:
resolution: {integrity: sha512-/veY75JbMK4j1yjvuUxuVsiS/hr/4iHs9FTT6cgTexxdE0Ly/glccBAkloH/DofkjRbZU3bnoj38mOmhkZ0lHw==}
@ -12312,6 +12331,18 @@ packages:
once: 1.4.0
path-is-absolute: 1.0.1
/global-agent/3.0.0:
resolution: {integrity: sha512-PT6XReJ+D07JvGoxQMkT6qji/jVNfX/h364XHZOWeRzy64sSFr+xJ5OX7LI3b4MPQzdL4H8Y8M0xzPpsVMwA8Q==}
engines: {node: '>=10.0'}
dependencies:
boolean: 3.2.0
es6-error: 4.1.1
matcher: 3.0.0
roarr: 2.15.4
semver: 7.3.7
serialize-error: 7.0.1
dev: false
/globals/11.12.0:
resolution: {integrity: sha512-WOBp/EEGUiIsJSp7wcv/y6MO+lV9UoncWqxuFfm8eBwzWNgyfBd6Gz+IeKQ9jCmyhoH99g15M3T+QaVHFjizVA==}
engines: {node: '>=4'}
@ -12324,6 +12355,13 @@ packages:
type-fest: 0.20.2
dev: true
/globalthis/1.0.3:
resolution: {integrity: sha512-sFdI5LyBiNTHjRd7cGPWapiHWMOXKyuBNX/cWJ3NfzrZQVa8GI/8cofCl74AOVqq9W5kNmguTIzJ/1s2gyI9wA==}
engines: {node: '>= 0.4'}
dependencies:
define-properties: 1.1.4
dev: false
/globalyzer/0.1.0:
resolution: {integrity: sha512-40oNTM9UfG6aBmuKxk/giHn5nQ8RVz/SS4Ir6zgzOv9/qC3kKZ9v4etGTcJbEl/NyVQH7FGU7d+X1egr57Md2Q==}
@ -13151,6 +13189,10 @@ packages:
resolution: {integrity: sha512-Bdboy+l7tA3OGW6FjyFHWkP5LuByj1Tk33Ljyq0axyzdk9//JSi2u3fP1QSmd1KNwq6VOKYGlAu87CisVir6Pw==}
dev: true
/json-stringify-safe/5.0.1:
resolution: {integrity: sha512-ZClg6AaYvamvYEE82d3Iyd3vSSIjQ+odgjaTzRuO3s7toCdFKczob2i0zCh7JE8kWn17yvAWhUVxvqGwUalsRA==}
dev: false
/json5/0.5.1:
resolution: {integrity: sha512-4xrs1aW+6N5DalkqSVA8fxh458CXvR99WU8WLKmq4v8eWAL86Xo3BVqyd3SkA9wEVjCMqyvvRRkshAdOnBp5rw==}
hasBin: true
@ -13427,6 +13469,13 @@ packages:
resolution: {integrity: sha512-y8j3a5/DkJCmS5x4dMCQL+OR0+2EAq3DOtio1COSHsmW2BGXnNCK3v12hJt1LrUz5iZH5g0LmuYOjDdI+czghA==}
dev: false
/matcher/3.0.0:
resolution: {integrity: sha512-OkeDaAZ/bQCxeFAozM55PKcKU0yJMPGifLwV4Qgjitu+5MoAfSQN4lsLJeXZ1b8w0x+/Emda6MZgXS1jvsapng==}
engines: {node: '>=10'}
dependencies:
escape-string-regexp: 4.0.0
dev: false
/mdast-util-definitions/5.1.1:
resolution: {integrity: sha512-rQ+Gv7mHttxHOBx2dkF4HWTg+EE+UR78ptQWDylzPKaQuVGdG4HIoY3SrS/pCp80nZ04greFvXbVFHT+uf0JVQ==}
dependencies:
@ -15918,6 +15967,18 @@ packages:
dependencies:
glob: 7.2.3
/roarr/2.15.4:
resolution: {integrity: sha512-CHhPh+UNHD2GTXNYhPWLnU8ONHdI+5DI+4EYIAOaiD63rHeYlZvyh8P+in5999TTSFgUYuKUAjzRI4mdh/p+2A==}
engines: {node: '>=8.0'}
dependencies:
boolean: 3.2.0
detect-node: 2.1.0
globalthis: 1.0.3
json-stringify-safe: 5.0.1
semver-compare: 1.0.0
sprintf-js: 1.1.2
dev: false
/rollup-plugin-inject/3.0.2:
resolution: {integrity: sha512-ptg9PQwzs3orn4jkgXJ74bfs5vYz1NCZlSQMBUA0wKcGp5i5pA1AO3fOUEte8enhGUC+iapTCzEWw2jEFFUO/w==}
deprecated: This package has been deprecated and is no longer maintained. Please use @rollup/plugin-inject.
@ -16048,6 +16109,10 @@ packages:
engines: {node: '>=6'}
dev: true
/semver-compare/1.0.0:
resolution: {integrity: sha512-YM3/ITh2MJ5MtzaM429anh+x2jiLVjqILF4m4oyQB18W7Ggea7BfqdH/wGMK7dDiMghv/6WG7znWMwUDzJiXow==}
dev: false
/semver/5.7.1:
resolution: {integrity: sha512-sauaDf/PZdVgrLTNYHRtpXa1iRiKcaebiKQ1BJdpQlWH2lCvexQdX55snPFyK7QzpudqbCI0qXFfOasHdyNDGQ==}
hasBin: true
@ -16064,6 +16129,13 @@ packages:
dependencies:
lru-cache: 6.0.0
/serialize-error/7.0.1:
resolution: {integrity: sha512-8I8TjW5KMOKsZQTvoxjuSIa7foAwPWGOts+6o7sgjz41/qMD9VQHEDxi6PBvK2l0MXUmqZyNpUK+T2tQaaElvw==}
engines: {node: '>=10'}
dependencies:
type-fest: 0.13.1
dev: false
/serialize-javascript/4.0.0:
resolution: {integrity: sha512-GaNA54380uFefWghODBWEGisLZFj00nS5ACs6yHa9nLqlLpVLO8ChDGeKRjZnV4Nh4n0Qi7nhYZD/9fCPzEqkw==}
dependencies:
@ -16363,6 +16435,10 @@ packages:
/sprintf-js/1.0.3:
resolution: {integrity: sha512-D9cPgkvLlV3t3IzL0D0YLvGA9Ahk4PcvVwUbN0dSGr1aP0Nrt4AEnTUbuGvquEC0mA64Gqt1fzirlRs5ibXx8g==}
/sprintf-js/1.1.2:
resolution: {integrity: sha512-VE0SOVEHCk7Qc8ulkWw3ntAzXuqf7S2lvwQaDLRnUeIEaKNQJzV6BwmLKhOqT61aGhfUMrXeaBk+oDGCzvhcug==}
dev: false
/srcset-parse/1.1.0:
resolution: {integrity: sha512-JWp4cG2eybkvKA1QUHGoNK6JDEYcOnSuhzNGjZuYUPqXreDl/VkkvP2sZW7Rmh+icuCttrR9ccb2WPIazyM/Cw==}
dev: true