Comparing version 4.0.1 to 4.1.0
@@ -64,2 +64,8 @@ /// <reference types="node" /> | ||
size?: number; | ||
/** | ||
* Implementation of `fetch` to use when making the API call. By default, | ||
* will use the browser context if available, and fall back to `node-fetch` | ||
* in node.js otherwise. | ||
*/ | ||
fetchImplementation?: FetchImplementation; | ||
} | ||
@@ -105,1 +111,25 @@ /** | ||
} | ||
export declare type FetchImplementation = (input: FetchRequestInfo, init?: FetchRequestInit) => Promise<FetchResponse>; | ||
export declare type FetchRequestInfo = any; | ||
export interface FetchResponse { | ||
readonly status: number; | ||
readonly statusText: string; | ||
readonly url: string; | ||
readonly body: unknown | null; | ||
arrayBuffer(): Promise<unknown>; | ||
blob(): Promise<unknown>; | ||
readonly headers: FetchHeaders; | ||
json(): Promise<any>; | ||
text(): Promise<string>; | ||
} | ||
export interface FetchRequestInit { | ||
method?: string; | ||
} | ||
export interface FetchHeaders { | ||
append(name: string, value: string): void; | ||
delete(name: string): void; | ||
get(name: string): string | null; | ||
has(name: string): boolean; | ||
set(name: string, value: string): void; | ||
forEach(callbackfn: (value: string, key: string) => void, thisArg?: any): void; | ||
} |
@@ -26,3 +26,2 @@ "use strict"; | ||
/* eslint-disable @typescript-eslint/no-explicit-any */ | ||
/* eslint-disable node/no-unsupported-features/node-builtins */ | ||
const fetch = hasFetch() ? window.fetch : node_fetch_1.default; | ||
@@ -36,4 +35,2 @@ function hasWindow() { | ||
let HttpsProxyAgent; | ||
// Figure out if we should be using a proxy. Only if it's required, load | ||
// the https-proxy-agent module as it adds startup cost. | ||
function loadProxy() { | ||
@@ -50,2 +47,32 @@ const proxy = process.env.HTTPS_PROXY || | ||
loadProxy(); | ||
function skipProxy(url) { | ||
var _a; | ||
const noProxyEnv = (_a = process.env.NO_PROXY) !== null && _a !== void 0 ? _a : process.env.no_proxy; | ||
if (!noProxyEnv) { | ||
return false; | ||
} | ||
const noProxyUrls = noProxyEnv.split(','); | ||
const parsedURL = new URL(url); | ||
return !!noProxyUrls.find(url => { | ||
if (url.startsWith('*.') || url.startsWith('.')) { | ||
url = url.replace('*', ''); | ||
return parsedURL.hostname.endsWith(url); | ||
} | ||
else { | ||
return url === parsedURL.origin || url === parsedURL.hostname; | ||
} | ||
}); | ||
} | ||
// Figure out if we should be using a proxy. Only if it's required, load | ||
// the https-proxy-agent module as it adds startup cost. | ||
function getProxy(url) { | ||
// If there is a match between the no_proxy env variables and the url, then do not proxy | ||
if (skipProxy(url)) { | ||
return undefined; | ||
// If there is not a match between the no_proxy env variables and the url, check to see if there should be a proxy | ||
} | ||
else { | ||
return loadProxy(); | ||
} | ||
} | ||
class Gaxios { | ||
@@ -69,3 +96,4 @@ /** | ||
async _defaultAdapter(opts) { | ||
const res = await fetch(opts.url, opts); | ||
const fetchImpl = opts.fetchImplementation || fetch; | ||
const res = (await fetchImpl(opts.url, opts)); | ||
const data = await this.getResponseData(opts, res); | ||
@@ -184,3 +212,3 @@ return this.translateResponse(opts, res, data); | ||
opts.method = opts.method || 'GET'; | ||
const proxy = loadProxy(); | ||
const proxy = getProxy(opts.url); | ||
if (proxy) { | ||
@@ -187,0 +215,0 @@ if (this.agentCache.has(proxy)) { |
# Changelog | ||
## [4.1.0](https://www.github.com/googleapis/gaxios/compare/v4.0.1...v4.1.0) (2020-12-08) | ||
### Features | ||
* add an option to configure the fetch impl ([#342](https://www.github.com/googleapis/gaxios/issues/342)) ([2e081ef](https://www.github.com/googleapis/gaxios/commit/2e081ef161d84aa435788e8d525d393dc7964117)) | ||
* add no_proxy env variable ([#361](https://www.github.com/googleapis/gaxios/issues/361)) ([efe72a7](https://www.github.com/googleapis/gaxios/commit/efe72a71de81d466160dde5da551f7a41acc3ac4)) | ||
### [4.0.1](https://www.github.com/googleapis/gaxios/compare/v4.0.0...v4.0.1) (2020-10-27) | ||
@@ -4,0 +12,0 @@ |
{ | ||
"name": "gaxios", | ||
"version": "4.0.1", | ||
"version": "4.1.0", | ||
"description": "A simple common HTTP client specifically for Google APIs and services.", | ||
@@ -14,3 +14,3 @@ "main": "build/src/index.js", | ||
"presystem-test": "npm run compile", | ||
"system-test": "mocha build/system-test --timeout 40000", | ||
"system-test": "mocha build/system-test --timeout 80000", | ||
"compile": "tsc -p .", | ||
@@ -54,5 +54,4 @@ "fix": "gts fix", | ||
"@types/ncp": "^2.0.1", | ||
"@types/nock": "^10.0.0", | ||
"@types/node": "^11.9.5", | ||
"@types/node-fetch": "^2.1.6", | ||
"@types/node-fetch": "^2.5.7", | ||
"@types/sinon": "^9.0.0", | ||
@@ -62,6 +61,4 @@ "@types/tmp": "0.2.0", | ||
"c8": "^7.0.0", | ||
"chai": "^4.2.0", | ||
"codecov": "^3.2.0", | ||
"cors": "^2.8.5", | ||
"execa": "^4.0.0", | ||
"execa": "^5.0.0", | ||
"express": "^4.16.4", | ||
@@ -68,0 +65,0 @@ "gts": "^3.0.0", |
@@ -112,2 +112,7 @@ # gaxios | ||
// Implementation of `fetch` to use when making the API call. By default, | ||
// will use the browser context if available, and fall back to `node-fetch` | ||
// in node.js otherwise. | ||
fetchImplementation?: typeof fetch; | ||
// Configuration for retrying of requests. | ||
@@ -114,0 +119,0 @@ retryConfig: { |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Environment variable access
Supply chain riskPackage accesses environment variables, which may be a sign of credential stuffing or data theft.
Found 2 instances in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
62151
45
641
157
7