@cloudpss/fetch 0.5.53 → 0.5.55

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1 +1 @@
1
- {"version":3,"file":"impl-node.d.ts","sourceRoot":"","sources":["../src/impl-node.ts"],"names":[],"mappings":"AAoEA,oBAAoB;AAEpB,eAAO,MAAM,KAAK,EAKb,OAAO,UAAU,CAAC,KAAK,CAAC;AAC7B,eAAO,MAAM,OAAO,EAAkB,OAAO,UAAU,CAAC,OAAO,CAAC;AAChE,eAAO,MAAM,QAAQ,EAA8B,OAAO,UAAU,CAAC,QAAQ,CAAC;AAC9E,eAAO,MAAM,OAAO,EAA6B,OAAO,UAAU,CAAC,OAAO,CAAC;AAC3E,eAAO,MAAM,IAAI,EAA0B,OAAO,UAAU,CAAC,IAAI,CAAC;AAClE,eAAO,MAAM,QAAQ,EAA8B,OAAO,UAAU,CAAC,QAAQ,CAAC;AAkC9E,wBAAwB;AACxB,eAAO,MAAM,SAAS;;;;;;;CAAc,CAAC;AAErC,eAAe,KAAK,CAAC"}
1
+ {"version":3,"file":"impl-node.d.ts","sourceRoot":"","sources":["../src/impl-node.ts"],"names":[],"mappings":"AAgBA,oBAAoB;AAEpB,eAAO,MAAM,KAAK,EAKb,OAAO,UAAU,CAAC,KAAK,CAAC;AAC7B,eAAO,MAAM,OAAO,EAAkB,OAAO,UAAU,CAAC,OAAO,CAAC;AAChE,eAAO,MAAM,QAAQ,EAA8B,OAAO,UAAU,CAAC,QAAQ,CAAC;AAC9E,eAAO,MAAM,OAAO,EAA6B,OAAO,UAAU,CAAC,OAAO,CAAC;AAC3E,eAAO,MAAM,IAAI,EAA0B,OAAO,UAAU,CAAC,IAAI,CAAC;AAClE,eAAO,MAAM,QAAQ,EAA8B,OAAO,UAAU,CAAC,QAAQ,CAAC;AAkC9E,wBAAwB;AACxB,eAAO,MAAM,SAAS;;;;;;;CAAc,CAAC;AAErC,eAAe,KAAK,CAAC"}
package/dist/impl-node.js CHANGED
@@ -1,53 +1,7 @@
1
- import { debuglog } from 'node:util';
2
1
  import { createRequire } from 'node:module';
3
- import undici from 'undici';
4
- import DispatcherBase from 'undici/lib/dispatcher/dispatcher-base.js';
5
- import symbols from 'undici/lib/core/symbols.js';
6
- import { getProxyForUrl } from './proxy-from-env.js';
7
- const { ProxyAgent, Agent, fetch: nodeFetch, Headers: NodeHeaders, Response: NodeResponse, Request: NodeRequest, WebSocket: NodeWebSocket, File: NodeFile, FormData: NodeFormData, } = undici;
8
- let logger = debuglog('cloudpss/fetch', (l) => (logger = l));
9
- const kAgents = Symbol('kAgents');
10
- const kAgent = Symbol('kAgent');
11
- /** 实现代理功能 */
12
- class AutoProxyAgent extends DispatcherBase {
13
- [kAgents] = new Map();
14
- [kAgent] = new Agent();
15
- /** 根据请求连接到代理 */
16
- [symbols.kDispatch](options, handler) {
17
- const { origin } = options;
18
- const proxy = origin ? getProxyForUrl(origin) : undefined;
19
- if (!proxy) {
20
- return this[kAgent].dispatch(options, handler);
21
- }
22
- logger(`auto proxy: to %s via %s`, origin, proxy);
23
- let agent = this[kAgents].get(proxy);
24
- if (!agent) {
25
- agent = new ProxyAgent(proxy);
26
- this[kAgents].set(proxy, agent);
27
- }
28
- return agent.dispatch(options, handler);
29
- }
30
- /** @inheritdoc */
31
- async [symbols.kClose]() {
32
- const tasks = [];
33
- for (const agent of this[kAgents].values()) {
34
- tasks.push(agent.close());
35
- }
36
- tasks.push(this[kAgent].close());
37
- await Promise.all(tasks);
38
- }
39
- /** @inheritdoc */
40
- async [symbols.kDestroy](err) {
41
- err ??= null;
42
- const tasks = [];
43
- for (const agent of this[kAgents].values()) {
44
- tasks.push(agent.destroy(err));
45
- }
46
- tasks.push(this[kAgent].destroy(err));
47
- await Promise.all(tasks);
48
- }
49
- }
50
- const dispatcher = new AutoProxyAgent();
2
+ import undici, { EnvHttpProxyAgent } from 'undici';
3
+ const { fetch: nodeFetch, Headers: NodeHeaders, Response: NodeResponse, Request: NodeRequest, WebSocket: NodeWebSocket, File: NodeFile, FormData: NodeFormData, } = undici;
4
+ const dispatcher = new EnvHttpProxyAgent();
51
5
  /** 自动支持代理的 fetch */
52
6
  // eslint-disable-next-line @typescript-eslint/promise-function-async
53
7
  export const fetch = function (url, init) {
@@ -1 +1 @@
1
- {"version":3,"file":"impl-node.js","sourceRoot":"","sources":["../src/impl-node.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAA4B,MAAM,WAAW,CAAC;AAC/D,OAAO,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAE5C,OAAO,MAAM,MAAM,QAAQ,CAAC;AAC5B,OAAO,cAAc,MAAM,0CAA0C,CAAC;AACtE,OAAO,OAAO,MAAM,4BAA4B,CAAC;AACjD,OAAO,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAC;AAErD,MAAM,EACF,UAAU,EACV,KAAK,EACL,KAAK,EAAE,SAAS,EAChB,OAAO,EAAE,WAAW,EACpB,QAAQ,EAAE,YAAY,EACtB,OAAO,EAAE,WAAW,EACpB,SAAS,EAAE,aAAa,EACxB,IAAI,EAAE,QAAQ,EACd,QAAQ,EAAE,YAAY,GACzB,GAAG,MAAM,CAAC;AAEX,IAAI,MAAM,GAAwB,QAAQ,CAAC,gBAAgB,EAAE,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,CAAC;AAClF,MAAM,OAAO,GAAG,MAAM,CAAC,SAAS,CAAC,CAAC;AAClC,MAAM,MAAM,GAAG,MAAM,CAAC,QAAQ,CAAC,CAAC;AAEhC,aAAa;AACb,MAAM,cAAe,SAAQ,cAAc;IACtB,CAAC,OAAO,CAAC,GAAG,IAAI,GAAG,EAA6B,CAAC;IACjD,CAAC,MAAM,CAAC,GAAG,IAAI,KAAK,EAAE,CAAC;IACxC,gBAAgB;IACP,CAAC,OAAO,CAAC,SAAS,CAAC,CAAC,OAAmC,EAAE,OAAoC;QAClG,MAAM,EAAE,M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CAAC;SAAM,IAAI,OAAQ,EAAE,EAAE,OAAqB,EAAE,SAAS,IAAI,UAAU,EAAE,CAAC;QACpE,UAAU,GAAI,EAAE,EAAE,OAAgC,EAAE,SAAmD,CAAC;IAC5G,CAAC;SAAM,CAAC;QACJ,OAAO,CAAC,WAAW,CAAC,kCAAkC,CAAC,CAAC;IAC5D,CAAC;AACL,CAAC;AAED,wBAAwB;AACxB,MAAM,CAAC,MAAM,SAAS,GAAG,UAAW,CAAC;AAErC,eAAe,KAAK,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cloudpss/fetch",
3
- "version": "0.5.53",
3
+ "version": "0.5.55",
4
4
  "author": "CloudPSS",
5
5
  "license": "MIT",
6
6
  "keywords": [
package/src/impl-node.ts CHANGED
@@ -1,14 +1,8 @@
1
- import { debuglog, type DebugLoggerFunction } from 'node:util';
2
1
  import { createRequire } from 'node:module';
3
- import type { RequestInfo as NodeRequestInfo, RequestInit as NodeRequestInit, WebSocketInit, Dispatcher } from 'undici';
4
- import undici from 'undici';
5
- import DispatcherBase from 'undici/lib/dispatcher/dispatcher-base.js';
6
- import symbols from 'undici/lib/core/symbols.js';
7
- import { getProxyForUrl } from './proxy-from-env.js';
2
+ import type { RequestInfo as NodeRequestInfo, RequestInit as NodeRequestInit, WebSocketInit } from 'undici';
3
+ import undici, { EnvHttpProxyAgent } from 'undici';
8
4
 
9
5
  const {
10
- ProxyAgent,
11
- Agent,
12
6
  fetch: nodeFetch,
13
7
  Headers: NodeHeaders,
14
8
  Response: NodeResponse,
@@ -18,53 +12,7 @@ const {
18
12
  FormData: NodeFormData,
19
13
  } = undici;
20
14
 
21
- let logger: DebugLoggerFunction = debuglog('cloudpss/fetch', (l) => (logger = l));
22
- const kAgents = Symbol('kAgents');
23
- const kAgent = Symbol('kAgent');
24
-
25
- /** 实现代理功能 */
26
- class AutoProxyAgent extends DispatcherBase {
27
- private readonly [kAgents] = new Map<string, undici.ProxyAgent>();
28
- private readonly [kAgent] = new Agent();
29
- /** 根据请求连接到代理 */
30
- override [symbols.kDispatch](options: Dispatcher.DispatchOptions, handler: Dispatcher.DispatchHandlers): boolean {
31
- const { origin } = options;
32
- const proxy = origin ? getProxyForUrl(origin) : undefined;
33
- if (!proxy) {
34
- return this[kAgent].dispatch(options, handler);
35
- }
36
- logger(`auto proxy: to %s via %s`, origin, proxy);
37
- let agent = this[kAgents].get(proxy);
38
- if (!agent) {
39
- agent = new ProxyAgent(proxy);
40
- this[kAgents].set(proxy, agent);
41
- }
42
- return agent.dispatch(options, handler);
43
- }
44
-
45
- /** @inheritdoc */
46
- override async [symbols.kClose](): Promise<void> {
47
- const tasks = [];
48
- for (const agent of this[kAgents].values()) {
49
- tasks.push(agent.close());
50
- }
51
- tasks.push(this[kAgent].close());
52
- await Promise.all(tasks);
53
- }
54
-
55
- /** @inheritdoc */
56
- override async [symbols.kDestroy](err?: Error | null): Promise<void> {
57
- err ??= null;
58
- const tasks = [];
59
- for (const agent of this[kAgents].values()) {
60
- tasks.push(agent.destroy(err));
61
- }
62
- tasks.push(this[kAgent].destroy(err));
63
- await Promise.all(tasks);
64
- }
65
- }
66
-
67
- const dispatcher = new AutoProxyAgent();
15
+ const dispatcher = new EnvHttpProxyAgent();
68
16
 
69
17
  /** 自动支持代理的 fetch */
70
18
  // eslint-disable-next-line @typescript-eslint/promise-function-async
@@ -1,9 +0,0 @@
1
- /**
2
- * Ref:
3
- * @see https://about.gitlab.com/blog/2021/01/27/we-need-to-talk-no-proxy/
4
- */
5
- /**
6
- * getProxyForUrl
7
- */
8
- export declare function getProxyForUrl(url: URL | string): string;
9
- //# sourceMappingURL=proxy-from-env.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"proxy-from-env.d.ts","sourceRoot":"","sources":["../src/proxy-from-env.ts"],"names":[],"mappings":"AAAA;;;GAGG;AA6FH;;GAEG;AACH,wBAAgB,cAAc,CAAC,GAAG,EAAE,GAAG,GAAG,MAAM,GAAG,MAAM,CA4BxD"}
@@ -1,120 +0,0 @@
1
- /**
2
- * Ref:
3
- * @see https://about.gitlab.com/blog/2021/01/27/we-need-to-talk-no-proxy/
4
- */
5
- const DEFAULT_PORTS = Object.freeze({
6
- 'ftp:': 21,
7
- 'http:': 80,
8
- 'https:': 443,
9
- 'ws:': 80,
10
- 'wss:': 443,
11
- });
12
- const NEVER_PROXY_PROTOCOL = new Set(['file:', 'data:', 'blob:']);
13
- /**
14
- * Get the value for an environment variable.
15
- */
16
- function getEnv(key) {
17
- return process.env[key.toLowerCase()] || process.env[key.toUpperCase()] || '';
18
- }
19
- /** parse no proxy */
20
- function parseNoProxy(noProxy) {
21
- if (!noProxy)
22
- return true;
23
- noProxy = noProxy.trim().toLowerCase();
24
- if (noProxy === '*')
25
- return false;
26
- const records = noProxy.split(/[,\s]+/);
27
- const patterns = [];
28
- let all = false;
29
- for (const record of records) {
30
- const trimmed = record.trim();
31
- if (!trimmed)
32
- continue;
33
- const parsed = /^(.+):(\d+)$/.exec(trimmed);
34
- let parsedHostname = parsed ? parsed[1] : trimmed;
35
- if (parsedHostname.startsWith('*.')) {
36
- parsedHostname = parsedHostname.slice(2);
37
- }
38
- else if (parsedHostname.startsWith('.') || parsedHostname.startsWith('*')) {
39
- parsedHostname = parsedHostname.slice(1);
40
- }
41
- const parsedPort = parsed ? Number.parseInt(parsed[2]) : undefined;
42
- if (!parsedHostname && !parsedPort) {
43
- all = true;
44
- break;
45
- }
46
- // deduplicate
47
- if (patterns.some((item) => item.suffix === parsedHostname && item.port === parsedPort))
48
- continue;
49
- patterns.push({
50
- suffix: parsedHostname,
51
- port: parsedPort,
52
- });
53
- }
54
- if (all)
55
- return false;
56
- if (!patterns.length)
57
- return true;
58
- return patterns;
59
- }
60
- let noProxyPatternsCache;
61
- let noProxyCache;
62
- /**
63
- * Determines whether a given URL should be proxied.
64
- */
65
- function shouldProxy(hostname, port) {
66
- const noProxy = getEnv('npm_config_no_proxy') || getEnv('no_proxy');
67
- let patterns;
68
- if (noProxy === noProxyCache) {
69
- patterns = noProxyPatternsCache;
70
- }
71
- else {
72
- noProxyCache = noProxy;
73
- patterns = noProxyPatternsCache = parseNoProxy(noProxy);
74
- }
75
- if (typeof patterns == 'boolean') {
76
- return patterns;
77
- }
78
- for (const pattern of patterns) {
79
- if (pattern.port && pattern.port !== port)
80
- continue;
81
- if (hostname === pattern.suffix)
82
- return false;
83
- if (hostname.length > pattern.suffix.length &&
84
- hostname.endsWith(pattern.suffix) &&
85
- hostname[hostname.length - pattern.suffix.length - 1] === '.')
86
- return false;
87
- }
88
- return true;
89
- }
90
- /**
91
- * getProxyForUrl
92
- */
93
- export function getProxyForUrl(url) {
94
- try {
95
- if (typeof url === 'string')
96
- url = new URL(url);
97
- }
98
- catch {
99
- return '';
100
- }
101
- const { protocol, hostname, port } = url;
102
- if (!hostname || NEVER_PROXY_PROTOCOL.has(protocol)) {
103
- return '';
104
- }
105
- const portNumber = (port ? Number.parseInt(port) : DEFAULT_PORTS[protocol]) || 0;
106
- if (!shouldProxy(hostname, portNumber)) {
107
- return ''; // Don't proxy URLs that match NO_PROXY.
108
- }
109
- const proto = protocol.slice(0, -1);
110
- const proxy = getEnv('npm_config_' + proto + '_proxy') ||
111
- getEnv(proto + '_proxy') ||
112
- getEnv('npm_config_proxy') ||
113
- getEnv('all_proxy');
114
- if (proxy && !proxy.includes('://')) {
115
- // Missing scheme in proxy, default to the requested URL's scheme.
116
- return proto + '://' + proxy;
117
- }
118
- return proxy;
119
- }
120
- //# sourceMappingURL=proxy-from-env.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"proxy-from-env.js","sourceRoot":"","sources":["../src/proxy-from-env.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,MAAM,aAAa,GAAG,MAAM,CAAC,MAAM,CAAC;IAChC,MAAM,EAAE,EAAE;IACV,OAAO,EAAE,EAAE;IACX,QAAQ,EAAE,GAAG;IACb,KAAK,EAAE,EAAE;IACT,MAAM,EAAE,GAAG;CACY,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AC,CAAC,CAAC,CAAC;IACpC,MAAM,KAAK,GACP,MAAM,CAAC,aAAa,GAAG,KAAK,GAAG,QAAQ,CAAC;QACxC,MAAM,CAAC,KAAK,GAAG,QAAQ,CAAC;QACxB,MAAM,CAAC,kBAAkB,CAAC;QAC1B,MAAM,CAAC,WAAW,CAAC,CAAC;IACxB,IAAI,KAAK,IAAI,CAAC,KAAK,CAAC,QAAQ,CAAC,KAAK,CAAC,EAAE,CAAC;QAClC,kEAAkE;QAClE,OAAO,KAAK,GAAG,KAAK,GAAG,KAAK,CAAC;IACjC,CAAC;IACD,OAAO,KAAK,CAAC;AACjB,CAAC"}
@@ -1,128 +0,0 @@
1
- /**
2
- * Ref:
3
- * @see https://about.gitlab.com/blog/2021/01/27/we-need-to-talk-no-proxy/
4
- */
5
-
6
- const DEFAULT_PORTS = Object.freeze({
7
- 'ftp:': 21,
8
- 'http:': 80,
9
- 'https:': 443,
10
- 'ws:': 80,
11
- 'wss:': 443,
12
- } as Record<string, number>);
13
-
14
- const NEVER_PROXY_PROTOCOL = new Set(['file:', 'data:', 'blob:']);
15
-
16
- /**
17
- * Get the value for an environment variable.
18
- */
19
- function getEnv(key: string): string {
20
- return process.env[key.toLowerCase()] || process.env[key.toUpperCase()] || '';
21
- }
22
-
23
- /** parsed no proxy pattern */
24
- type Pattern = {
25
- suffix: string;
26
- port: number | undefined;
27
- };
28
-
29
- /** parse no proxy */
30
- function parseNoProxy(noProxy: string | undefined): boolean | Pattern[] {
31
- if (!noProxy) return true;
32
- noProxy = noProxy.trim().toLowerCase();
33
- if (noProxy === '*') return false;
34
-
35
- const records = noProxy.split(/[,\s]+/);
36
- const patterns: Pattern[] = [];
37
- let all = false;
38
- for (const record of records) {
39
- const trimmed = record.trim();
40
- if (!trimmed) continue;
41
- const parsed = /^(.+):(\d+)$/.exec(trimmed);
42
- let parsedHostname = parsed ? parsed[1]! : trimmed;
43
- if (parsedHostname.startsWith('*.')) {
44
- parsedHostname = parsedHostname.slice(2);
45
- } else if (parsedHostname.startsWith('.') || parsedHostname.startsWith('*')) {
46
- parsedHostname = parsedHostname.slice(1);
47
- }
48
- const parsedPort = parsed ? Number.parseInt(parsed[2]!) : undefined;
49
- if (!parsedHostname && !parsedPort) {
50
- all = true;
51
- break;
52
- }
53
- // deduplicate
54
- if (patterns.some((item) => item.suffix === parsedHostname && item.port === parsedPort)) continue;
55
- patterns.push({
56
- suffix: parsedHostname,
57
- port: parsedPort,
58
- });
59
- }
60
- if (all) return false;
61
- if (!patterns.length) return true;
62
- return patterns;
63
- }
64
-
65
- let noProxyPatternsCache: boolean | readonly Pattern[];
66
- let noProxyCache: string;
67
-
68
- /**
69
- * Determines whether a given URL should be proxied.
70
- */
71
- function shouldProxy(hostname: string, port: number): boolean {
72
- const noProxy = getEnv('npm_config_no_proxy') || getEnv('no_proxy');
73
- let patterns;
74
- if (noProxy === noProxyCache) {
75
- patterns = noProxyPatternsCache;
76
- } else {
77
- noProxyCache = noProxy;
78
- patterns = noProxyPatternsCache = parseNoProxy(noProxy);
79
- }
80
-
81
- if (typeof patterns == 'boolean') {
82
- return patterns;
83
- }
84
- for (const pattern of patterns) {
85
- if (pattern.port && pattern.port !== port) continue;
86
- if (hostname === pattern.suffix) return false;
87
- if (
88
- hostname.length > pattern.suffix.length &&
89
- hostname.endsWith(pattern.suffix) &&
90
- hostname[hostname.length - pattern.suffix.length - 1] === '.'
91
- )
92
- return false;
93
- }
94
- return true;
95
- }
96
-
97
- /**
98
- * getProxyForUrl
99
- */
100
- export function getProxyForUrl(url: URL | string): string {
101
- try {
102
- if (typeof url === 'string') url = new URL(url);
103
- } catch {
104
- return '';
105
- }
106
-
107
- const { protocol, hostname, port } = url;
108
- if (!hostname || NEVER_PROXY_PROTOCOL.has(protocol)) {
109
- return '';
110
- }
111
-
112
- const portNumber = (port ? Number.parseInt(port) : DEFAULT_PORTS[protocol]!) || 0;
113
- if (!shouldProxy(hostname, portNumber)) {
114
- return ''; // Don't proxy URLs that match NO_PROXY.
115
- }
116
-
117
- const proto = protocol.slice(0, -1);
118
- const proxy =
119
- getEnv('npm_config_' + proto + '_proxy') ||
120
- getEnv(proto + '_proxy') ||
121
- getEnv('npm_config_proxy') ||
122
- getEnv('all_proxy');
123
- if (proxy && !proxy.includes('://')) {
124
- // Missing scheme in proxy, default to the requested URL's scheme.
125
- return proto + '://' + proxy;
126
- }
127
- return proxy;
128
- }
package/src/undici.d.ts DELETED
@@ -1,30 +0,0 @@
1
- /* eslint-disable jsdoc/require-jsdoc */
2
-
3
- declare module 'undici/lib/core/symbols.js' {
4
- const kClose: unique symbol;
5
- const kDestroy: unique symbol;
6
- const kDispatch: unique symbol;
7
-
8
- export = {
9
- kClose,
10
- kDestroy,
11
- kDispatch,
12
- } as const;
13
- }
14
-
15
- declare module 'undici/lib/dispatcher/dispatcher-base.js' {
16
- import { Dispatcher } from 'undici';
17
- import symbols from 'undici/lib/core/symbols.js';
18
- class DispatcherBase extends Dispatcher {
19
- // Should not error.
20
- // eslint-disable-next-line @typescript-eslint/unified-signatures
21
- protected [symbols.kDestroy](err?: Error | null): Promise<void>;
22
- // Should not error.
23
- protected [symbols.kClose](): Promise<void>;
24
- protected [symbols.kDispatch](
25
- options: Dispatcher.DispatchOptions,
26
- handler: Dispatcher.DispatchHandlers,
27
- ): boolean;
28
- }
29
- export = DispatcherBase;
30
- }
@@ -1,460 +0,0 @@
1
- import { getProxyForUrl } from '../dist/proxy-from-env.js';
2
-
3
- /**
4
- * Runs the callback with process.env temporarily set to env.
5
- * @param {Record<string, string>} env env
6
- * @param {()=>void} callback callback
7
- */
8
- function runWithEnv(env, callback) {
9
- var originalEnv = process.env;
10
- process.env = env;
11
- try {
12
- callback();
13
- } finally {
14
- process.env = originalEnv;
15
- }
16
- }
17
-
18
- /**
19
- * Defines a test case that checks whether getProxyForUrl(input) === expected.
20
- * @param {Record<string, string>} env env
21
- * @param {string} expected expected
22
- * @param {string | URL} input input
23
- */
24
- function testProxyUrl(env, expected, input) {
25
- // Copy object to make sure that the in param does not get modified between
26
- // the call of this function and the use of it below.
27
- env = { ...env };
28
-
29
- var title = 'getProxyForUrl(' + JSON.stringify(input) + ')' + ' === ' + JSON.stringify(expected);
30
-
31
- it(title, function () {
32
- var actual;
33
- runWithEnv(env, function () {
34
- actual = getProxyForUrl(input);
35
- });
36
- expect(actual).toBe(expected);
37
- });
38
- }
39
-
40
- describe('getProxyForUrl', function () {
41
- describe('No proxy variables', function () {
42
- var env = { TZ: '' };
43
- testProxyUrl(env, '', 'http://example.com');
44
- testProxyUrl(env, '', 'https://example.com');
45
- testProxyUrl(env, '', 'ftp://example.com');
46
- });
47
-
48
- describe('Invalid URLs', function () {
49
- var env = { ALL_PROXY: 'http://unexpected.proxy' };
50
- testProxyUrl(env, '', 'bogus');
51
- testProxyUrl(env, '', '//example.com');
52
- testProxyUrl(env, '', '://example.com');
53
- testProxyUrl(env, '', '://');
54
- testProxyUrl(env, '', '/path');
55
- testProxyUrl(env, '', '');
56
- testProxyUrl(env, '', 'http:');
57
- testProxyUrl(env, '', 'http:/');
58
- testProxyUrl(env, '', 'http://');
59
- testProxyUrl(env, '', 'prototype://');
60
- testProxyUrl(env, '', 'hasOwnProperty://');
61
- testProxyUrl(env, '', '__proto__://');
62
- });
63
-
64
- describe('http_proxy and HTTP_PROXY', function () {
65
- var env = { HTTP_PROXY: 'http://http-proxy', http_proxy: '' };
66
-
67
- testProxyUrl(env, '', 'https://example');
68
- testProxyUrl(env, 'http://http-proxy', new URL('http://example'));
69
-
70
- env.http_proxy = 'http://priority';
71
- testProxyUrl(env, 'http://priority', 'http://example');
72
- });
73
-
74
- describe('http_proxy with non-sensical value', function () {
75
- // Crazy values should be passed as-is. It is the responsibility of the
76
- // one who launches the application that the value makes sense.
77
- // TODO: Should we be stricter and perform validation?
78
- var env = { HTTP_PROXY: 'Crazy \n!() { ::// }' };
79
- testProxyUrl(env, 'Crazy \n!() { ::// }', 'http://wow');
80
-
81
- // The implementation assumes that the HTTP_PROXY environment variable is
82
- // somewhat reasonable, and if the scheme is missing, it is added.
83
- // Garbage in, garbage out some would say...
84
- env.HTTP_PROXY = 'crazy without colon slash slash';
85
- testProxyUrl(env, 'http://crazy without colon slash slash', 'http://wow');
86
- });
87
-
88
- describe('https_proxy and HTTPS_PROXY', function () {
89
- var env = { HTTP_PROXY: '', HTTPS_PROXY: '', https_proxy: '' };
90
- // Assert that there is no fall back to http_proxy
91
- env.HTTP_PROXY = 'http://unexpected.proxy';
92
- testProxyUrl(env, '', 'https://example');
93
-
94
- env.HTTPS_PROXY = 'http://https-proxy';
95
- testProxyUrl(env, 'http://https-proxy', 'https://example');
96
-
97
- env.https_proxy = 'http://priority';
98
- testProxyUrl(env, 'http://priority', 'https://example');
99
- });
100
-
101
- describe('ftp_proxy', function () {
102
- var env = { FTP_PROXY: '' };
103
- // Something else than http_proxy / https, as a sanity check.
104
- env.FTP_PROXY = 'http://ftp-proxy';
105
-
106
- testProxyUrl(env, 'http://ftp-proxy', 'ftp://example');
107
- testProxyUrl(env, '', 'ftps://example');
108
- });
109
-
110
- describe('all_proxy', function () {
111
- var env = { ALL_PROXY: '', all_proxy: '' };
112
- env.ALL_PROXY = 'http://catch-all';
113
- testProxyUrl(env, 'http://catch-all', 'https://example');
114
-
115
- env.all_proxy = 'http://priority';
116
- testProxyUrl(env, 'http://priority', 'https://example');
117
- });
118
-
119
- describe('all_proxy without scheme', function () {
120
- var env = { ALL_PROXY: '' };
121
- env.ALL_PROXY = 'noscheme';
122
- testProxyUrl(env, 'http://noscheme', 'http://example');
123
- testProxyUrl(env, 'https://noscheme', 'https://example');
124
-
125
- // The module does not impose restrictions on the scheme.
126
- testProxyUrl(env, 'bogus-scheme://noscheme', 'bogus-scheme://example');
127
-
128
- // But the URL should still be valid.
129
- testProxyUrl(env, '', 'bogus');
130
- });
131
-
132
- describe('no_proxy empty', function () {
133
- var env = { HTTPS_PROXY: '', NO_PROXY: '' };
134
- env.HTTPS_PROXY = 'http://proxy';
135
-
136
- // NO_PROXY set but empty.
137
- env.NO_PROXY = '';
138
- testProxyUrl(env, 'http://proxy', 'https://example');
139
-
140
- // No entries in NO_PROXY (comma).
141
- env.NO_PROXY = ',';
142
- testProxyUrl(env, 'http://proxy', 'https://example');
143
-
144
- // No entries in NO_PROXY (whitespace).
145
- env.NO_PROXY = ' ';
146
- testProxyUrl(env, 'http://proxy', 'https://example');
147
-
148
- // No entries in NO_PROXY (multiple whitespace / commas).
149
- env.NO_PROXY = ',\t,,,\n, ,\r';
150
- testProxyUrl(env, 'http://proxy', 'https://example');
151
- });
152
-
153
- describe('no_proxy=example (single host)', function () {
154
- var env = { HTTP_PROXY: '', NO_PROXY: '' };
155
- env.HTTP_PROXY = 'http://proxy';
156
-
157
- env.NO_PROXY = 'example';
158
- testProxyUrl(env, '', 'http://example');
159
- testProxyUrl(env, '', 'http://example:80');
160
- testProxyUrl(env, '', 'http://example:0');
161
- testProxyUrl(env, '', 'http://example:1337');
162
- testProxyUrl(env, '', 'http://sub.example');
163
- testProxyUrl(env, '', 'http://a.b.example');
164
- testProxyUrl(env, 'http://proxy', 'http://prefexample');
165
- testProxyUrl(env, 'http://proxy', 'http://example.no');
166
- testProxyUrl(env, 'http://proxy', 'http://host/example');
167
- });
168
-
169
- describe('no_proxy=sub.example (subdomain)', function () {
170
- var env = { HTTP_PROXY: '', NO_PROXY: '' };
171
- env.HTTP_PROXY = 'http://proxy';
172
-
173
- env.NO_PROXY = 'sub.example';
174
- testProxyUrl(env, 'http://proxy', 'http://example');
175
- testProxyUrl(env, 'http://proxy', 'http://example:80');
176
- testProxyUrl(env, 'http://proxy', 'http://example:0');
177
- testProxyUrl(env, 'http://proxy', 'http://example:1337');
178
- testProxyUrl(env, '', 'http://sub.example');
179
- testProxyUrl(env, '', 'http://no.sub.example');
180
- testProxyUrl(env, 'http://proxy', 'http://sub-example');
181
- testProxyUrl(env, 'http://proxy', 'http://example.sub');
182
- });
183
-
184
- describe('no_proxy=example:80 (host + port)', function () {
185
- var env = { HTTP_PROXY: '', NO_PROXY: '' };
186
- env.HTTP_PROXY = 'http://proxy';
187
-
188
- env.NO_PROXY = 'example:80';
189
- testProxyUrl(env, '', 'http://example');
190
- testProxyUrl(env, '', 'http://example:80');
191
- testProxyUrl(env, 'http://proxy', 'http://example:0');
192
- testProxyUrl(env, 'http://proxy', 'http://example:1337');
193
- testProxyUrl(env, '', 'http://sub.example');
194
- testProxyUrl(env, 'http://proxy', 'http://prefexample');
195
- testProxyUrl(env, 'http://proxy', 'http://example.no');
196
- testProxyUrl(env, '', 'http://a.b.example');
197
- });
198
-
199
- describe('no_proxy=.example (host suffix)', function () {
200
- var env = { HTTP_PROXY: '', NO_PROXY: '' };
201
- env.HTTP_PROXY = 'http://proxy';
202
-
203
- env.NO_PROXY = '.example';
204
- testProxyUrl(env, '', 'http://example');
205
- testProxyUrl(env, '', 'http://example:80');
206
- testProxyUrl(env, '', 'http://example:1337');
207
- testProxyUrl(env, '', 'http://sub.example');
208
- testProxyUrl(env, '', 'http://sub.example:80');
209
- testProxyUrl(env, '', 'http://sub.example:1337');
210
- testProxyUrl(env, '', 'http://a.b.example');
211
- testProxyUrl(env, 'http://proxy', 'http://prefexample');
212
- testProxyUrl(env, 'http://proxy', 'http://example.no');
213
- });
214
-
215
- describe('no_proxy=*', function () {
216
- var env = { HTTP_PROXY: '', NO_PROXY: '' };
217
- env.HTTP_PROXY = 'http://proxy';
218
- env.NO_PROXY = '*';
219
- testProxyUrl(env, '', 'http://example.com');
220
-
221
- env.NO_PROXY = '* , * ,*';
222
- testProxyUrl(env, '', 'http://example.com');
223
-
224
- env.NO_PROXY = '* , * , idk';
225
- testProxyUrl(env, '', 'http://example.com');
226
- });
227
-
228
- describe('no_proxy=*.example (host suffix with *.)', function () {
229
- var env = { HTTP_PROXY: '', NO_PROXY: '' };
230
- env.HTTP_PROXY = 'http://proxy';
231
-
232
- env.NO_PROXY = '*.example';
233
- testProxyUrl(env, '', 'http://example');
234
- testProxyUrl(env, '', 'http://example:80');
235
- testProxyUrl(env, '', 'http://example:1337');
236
- testProxyUrl(env, '', 'http://sub.example');
237
- testProxyUrl(env, '', 'http://sub.example:80');
238
- testProxyUrl(env, '', 'http://sub.example:1337');
239
- testProxyUrl(env, '', 'http://a.b.example');
240
- testProxyUrl(env, 'http://proxy', 'http://prefexample');
241
- testProxyUrl(env, 'http://proxy', 'http://example.no');
242
- });
243
-
244
- describe('no_proxy=*example (substring suffix)', function () {
245
- var env = { HTTP_PROXY: '', NO_PROXY: '' };
246
- env.HTTP_PROXY = 'http://proxy';
247
-
248
- env.NO_PROXY = '*example';
249
- testProxyUrl(env, '', 'http://example');
250
- testProxyUrl(env, '', 'http://example:80');
251
- testProxyUrl(env, '', 'http://example:1337');
252
- testProxyUrl(env, '', 'http://sub.example');
253
- testProxyUrl(env, '', 'http://sub.example:80');
254
- testProxyUrl(env, '', 'http://sub.example:1337');
255
- testProxyUrl(env, '', 'http://a.b.example');
256
- testProxyUrl(env, 'http://proxy', 'http://prefexample');
257
- testProxyUrl(env, 'http://proxy', 'http://example.no');
258
- testProxyUrl(env, 'http://proxy', 'http://host/example');
259
- });
260
-
261
- describe('no_proxy=.*example (arbitrary wildcards are NOT supported)', function () {
262
- var env = { HTTP_PROXY: '', NO_PROXY: '' };
263
- env.HTTP_PROXY = 'http://proxy';
264
-
265
- env.NO_PROXY = '.*example';
266
- testProxyUrl(env, 'http://proxy', 'http://example');
267
- testProxyUrl(env, 'http://proxy', 'http://sub.example');
268
- testProxyUrl(env, 'http://proxy', 'http://sub.example');
269
- testProxyUrl(env, 'http://proxy', 'http://prefexample');
270
- testProxyUrl(env, 'http://proxy', 'http://x.prefexample');
271
- testProxyUrl(env, 'http://proxy', 'http://a.b.example');
272
- });
273
-
274
- describe('no_proxy=.example,*.example (dedupe)', function () {
275
- var env = { HTTP_PROXY: '', NO_PROXY: '' };
276
- env.HTTP_PROXY = 'http://proxy';
277
-
278
- env.NO_PROXY = '*.example,.example';
279
- testProxyUrl(env, '', 'http://example');
280
- testProxyUrl(env, '', 'http://example:80');
281
- testProxyUrl(env, '', 'http://example:1337');
282
- testProxyUrl(env, '', 'http://sub.example');
283
- testProxyUrl(env, '', 'http://sub.example:80');
284
- testProxyUrl(env, '', 'http://sub.example:1337');
285
- testProxyUrl(env, '', 'http://a.b.example');
286
- testProxyUrl(env, 'http://proxy', 'http://prefexample');
287
- testProxyUrl(env, 'http://proxy', 'http://example.no');
288
- testProxyUrl(env, 'http://proxy', 'http://host/example');
289
- });
290
-
291
- describe('no_proxy=[::1],[::2]:80,10.0.0.1,10.0.0.2:80 (IP addresses)', function () {
292
- var env = { HTTP_PROXY: '', NO_PROXY: '' };
293
- env.HTTP_PROXY = 'http://proxy';
294
-
295
- env.NO_PROXY = '[::1],[::2]:80,10.0.0.1,10.0.0.2:80';
296
- testProxyUrl(env, '', 'http://[::1]/');
297
- testProxyUrl(env, '', 'http://[::1]:80/');
298
- testProxyUrl(env, '', 'http://[::1]:1337/');
299
-
300
- testProxyUrl(env, '', 'http://[::2]/');
301
- testProxyUrl(env, '', 'http://[::2]:80/');
302
- testProxyUrl(env, 'http://proxy', 'http://[::2]:1337/');
303
-
304
- testProxyUrl(env, '', 'http://10.0.0.1/');
305
- testProxyUrl(env, '', 'http://10.0.0.1:80/');
306
- testProxyUrl(env, '', 'http://10.0.0.1:1337/');
307
-
308
- testProxyUrl(env, '', 'http://10.0.0.2/');
309
- testProxyUrl(env, '', 'http://10.0.0.2:80/');
310
- testProxyUrl(env, 'http://proxy', 'http://10.0.0.2:1337/');
311
- });
312
-
313
- describe('no_proxy=127.0.0.1/32 (CIDR is NOT supported)', function () {
314
- var env = { HTTP_PROXY: '', NO_PROXY: '' };
315
- env.HTTP_PROXY = 'http://proxy';
316
-
317
- env.NO_PROXY = '127.0.0.1/32';
318
- testProxyUrl(env, 'http://proxy', 'http://127.0.0.1');
319
- testProxyUrl(env, 'http://proxy', 'http://127.0.0.1/32');
320
- });
321
-
322
- describe('no_proxy=127.0.0.1 does NOT match localhost', function () {
323
- var env = { HTTP_PROXY: '', NO_PROXY: '' };
324
- env.HTTP_PROXY = 'http://proxy';
325
-
326
- env.NO_PROXY = '127.0.0.1';
327
- testProxyUrl(env, '', 'http://127.0.0.1');
328
- // We're not performing DNS queries, so this shouldn't match.
329
- testProxyUrl(env, 'http://proxy', 'http://localhost');
330
- });
331
-
332
- describe('no_proxy with protocols that have a default port', function () {
333
- /** @type {Record<string, string>} */
334
- var env = {};
335
- env['WS_PROXY'] = 'http://ws';
336
- env['WSS_PROXY'] = 'http://wss';
337
- env['HTTP_PROXY'] = 'http://http';
338
- env['HTTPS_PROXY'] = 'http://https';
339
- env['FTP_PROXY'] = 'http://ftp';
340
- env['ALL_PROXY'] = 'http://all';
341
-
342
- env['NO_PROXY'] = 'xxx:21,xxx:70,xxx:80,xxx:443';
343
-
344
- testProxyUrl(env, '', 'http://xxx');
345
- testProxyUrl(env, '', 'http://xxx:80');
346
- testProxyUrl(env, 'http://http', 'http://xxx:1337');
347
-
348
- testProxyUrl(env, '', 'ws://xxx');
349
- testProxyUrl(env, '', 'ws://xxx:80');
350
- testProxyUrl(env, 'http://ws', 'ws://xxx:1337');
351
-
352
- testProxyUrl(env, '', 'https://xxx');
353
- testProxyUrl(env, '', 'https://xxx:443');
354
- testProxyUrl(env, 'http://https', 'https://xxx:1337');
355
-
356
- testProxyUrl(env, '', 'wss://xxx');
357
- testProxyUrl(env, '', 'wss://xxx:443');
358
- testProxyUrl(env, 'http://wss', 'wss://xxx:1337');
359
-
360
- testProxyUrl(env, '', 'ftp://xxx');
361
- testProxyUrl(env, '', 'ftp://xxx:21');
362
- testProxyUrl(env, 'http://ftp', 'ftp://xxx:1337');
363
- });
364
-
365
- describe('no_proxy should not be case-sensitive', function () {
366
- var env = { HTTP_PROXY: '', NO_PROXY: '' };
367
- env.HTTP_PROXY = 'http://proxy';
368
- env.NO_PROXY = 'XXX,YYY,ZzZ';
369
-
370
- testProxyUrl(env, '', 'http://xxx');
371
- testProxyUrl(env, '', 'http://XXX');
372
- testProxyUrl(env, '', 'http://yyy');
373
- testProxyUrl(env, '', 'http://YYY');
374
- testProxyUrl(env, '', 'http://ZzZ');
375
- testProxyUrl(env, '', 'http://zZz');
376
- });
377
-
378
- describe('NPM proxy configuration', function () {
379
- describe('npm_config_http_proxy should work', function () {
380
- /** @type {Record<string, string>} */
381
- var env = {};
382
- env['npm_config_http_proxy'] = 'http://http-proxy';
383
-
384
- testProxyUrl(env, '', 'https://example');
385
- testProxyUrl(env, 'http://http-proxy', 'http://example');
386
-
387
- env['npm_config_http_proxy'] = 'http://priority';
388
- testProxyUrl(env, 'http://priority', 'http://example');
389
- });
390
- describe('npm_config_http_proxy should take precedence over HTTP_PROXY and npm_config_proxy', function () {
391
- /** @type {Record<string, string>} */
392
- var env = {};
393
- env['npm_config_http_proxy'] = 'http://http-proxy';
394
- env['npm_config_proxy'] = 'http://unexpected-proxy';
395
- env['HTTP_PROXY'] = 'http://unexpected-proxy';
396
-
397
- testProxyUrl(env, 'http://http-proxy', 'http://example');
398
- });
399
- describe('npm_config_https_proxy should work', function () {
400
- /** @type {Record<string, string>} */
401
- var env = {};
402
- env['npm_config_http_proxy'] = 'http://unexpected.proxy';
403
- testProxyUrl(env, '', 'https://example');
404
-
405
- env['npm_config_https_proxy'] = 'http://https-proxy';
406
- testProxyUrl(env, 'http://https-proxy', 'https://example');
407
-
408
- env['npm_config_https_proxy'] = 'http://priority';
409
- testProxyUrl(env, 'http://priority', 'https://example');
410
- });
411
- describe('npm_config_https_proxy should take precedence over HTTPS_PROXY and npm_config_proxy', function () {
412
- /** @type {Record<string, string>} */
413
- var env = {};
414
- env['npm_config_https_proxy'] = 'http://https-proxy';
415
- env['npm_config_proxy'] = 'http://unexpected-proxy';
416
- env['HTTPS_PROXY'] = 'http://unexpected-proxy';
417
-
418
- testProxyUrl(env, 'http://https-proxy', 'https://example');
419
- });
420
- describe('npm_config_proxy should work', function () {
421
- /** @type {Record<string, string>} */
422
- var env = {};
423
- env['npm_config_proxy'] = 'http://http-proxy';
424
- testProxyUrl(env, 'http://http-proxy', 'http://example');
425
- testProxyUrl(env, 'http://http-proxy', 'https://example');
426
-
427
- env['npm_config_proxy'] = 'http://priority';
428
- testProxyUrl(env, 'http://priority', 'http://example');
429
- testProxyUrl(env, 'http://priority', 'https://example');
430
- });
431
- describe('HTTP_PROXY and HTTPS_PROXY should take precedence over npm_config_proxy', function () {
432
- /** @type {Record<string, string>} */
433
- var env = {};
434
- env['HTTP_PROXY'] = 'http://http-proxy';
435
- env['HTTPS_PROXY'] = 'http://https-proxy';
436
- env['npm_config_proxy'] = 'http://unexpected-proxy';
437
- testProxyUrl(env, 'http://http-proxy', 'http://example');
438
- testProxyUrl(env, 'http://https-proxy', 'https://example');
439
- });
440
- describe('npm_config_no_proxy should work', function () {
441
- /** @type {Record<string, string>} */
442
- var env = {};
443
- env['HTTP_PROXY'] = 'http://proxy';
444
- env['npm_config_no_proxy'] = 'example';
445
-
446
- testProxyUrl(env, '', 'http://example');
447
- testProxyUrl(env, 'http://proxy', 'http://otherwebsite');
448
- });
449
- describe('npm_config_no_proxy should take precedence over NO_PROXY', function () {
450
- /** @type {Record<string, string>} */
451
- var env = {};
452
- env['HTTP_PROXY'] = 'http://proxy';
453
- env['NO_PROXY'] = 'otherwebsite';
454
- env['npm_config_no_proxy'] = 'example';
455
-
456
- testProxyUrl(env, '', 'http://example');
457
- testProxyUrl(env, 'http://proxy', 'http://otherwebsite');
458
- });
459
- });
460
- });