staff-mcp 1.1.0 → 1.1.1
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.
- package/README.md +3 -1
- package/README_zh.md +3 -1
- package/dist/src/utils/proxy.d.ts +64 -12
- package/dist/src/utils/proxy.js +329 -44
- package/dist/src/utils/proxy.js.map +1 -1
- package/dist/tests/proxy-no-proxy.test.d.ts +1 -0
- package/dist/tests/proxy-no-proxy.test.js +156 -0
- package/dist/tests/proxy-no-proxy.test.js.map +1 -0
- package/dist/tests/proxy.test.js +4 -4
- package/dist/tests/proxy.test.js.map +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -123,7 +123,9 @@ staff-mcp automatically honors the standard proxy environment variables for **al
|
|
|
123
123
|
|
|
124
124
|
```bash
|
|
125
125
|
export HTTPS_PROXY=http://proxy.company.com:8080
|
|
126
|
-
export NO_PROXY=localhost,127.0.0.1
|
|
126
|
+
export NO_PROXY=localhost,127.0.0.1,10.0.0.0/8,.internal.example.com
|
|
127
|
+
# NO_PROXY supports: exact hosts/IPs, domain suffixes (.example.com or bare example.com),
|
|
128
|
+
# "*" wildcard, host:port qualifiers, and IPv4/IPv6 CIDR ranges (e.g. 172.16.0.0/12, fd00::/8)
|
|
127
129
|
npx -y staff-mcp@latest -t reverse --ru https://chat.example.com/api/mcp/reverse --rt <token> --rn myserver
|
|
128
130
|
```
|
|
129
131
|
|
package/README_zh.md
CHANGED
|
@@ -124,7 +124,9 @@ staff-mcp 会自动识别标准代理环境变量,作用于**所有**出站请
|
|
|
124
124
|
|
|
125
125
|
```bash
|
|
126
126
|
export HTTPS_PROXY=http://proxy.company.com:8080
|
|
127
|
-
export NO_PROXY=localhost,127.0.0.1
|
|
127
|
+
export NO_PROXY=localhost,127.0.0.1,10.0.0.0/8,.internal.example.com
|
|
128
|
+
# NO_PROXY 支持:精确主机/IP、域名后缀(.example.com 或裸写 example.com)、
|
|
129
|
+
# "*" 通配、host:port 端口限定,以及 IPv4/IPv6 CIDR 网段(如 172.16.0.0/12、fd00::/8)
|
|
128
130
|
npx -y staff-mcp@latest -t reverse --ru https://chat.example.com/api/mcp/reverse --rt <token> --rn myserver
|
|
129
131
|
```
|
|
130
132
|
|
|
@@ -1,18 +1,70 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
import { Agent, Dispatcher } from "undici";
|
|
2
|
+
/**
|
|
3
|
+
* Whether proxy environment variables are present (NO_PROXY alone does not count).
|
|
4
|
+
*/
|
|
4
5
|
export declare function hasProxyEnv(env?: NodeJS.ProcessEnv): boolean;
|
|
6
|
+
export type NoProxyEntryKind = "wildcard" | "exact" | "suffix" | "cidr4" | "cidr6";
|
|
7
|
+
export interface NoProxyEntry {
|
|
8
|
+
kind: NoProxyEntryKind;
|
|
9
|
+
/** normalized host: lowercase, no trailing dot, no IPv6 brackets */
|
|
10
|
+
host: string;
|
|
11
|
+
/** optional port restriction; null = any port */
|
|
12
|
+
port: number | null;
|
|
13
|
+
/** network base for cidr4 (32-bit int) / cidr6 (128-bit bigint) */
|
|
14
|
+
network?: number | bigint;
|
|
15
|
+
/** prefix length for cidr kinds */
|
|
16
|
+
bits?: number;
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* Parse a NO_PROXY value into matchable entries.
|
|
20
|
+
* Supported: "*", exact hosts, ".example.com"/"*.example.com" suffixes,
|
|
21
|
+
* bare domains (exact + subdomains, curl semantics), "host:port",
|
|
22
|
+
* IPv4/IPv6 literals and CIDR ranges ("10.0.0.0/8", "fd00::/8").
|
|
23
|
+
*/
|
|
24
|
+
export declare function parseNoProxy(value: string | undefined | null): NoProxyEntry[];
|
|
25
|
+
/** Whether a target host:port matches any NO_PROXY entry (i.e. should bypass the proxy). */
|
|
26
|
+
export declare function matchesNoProxy(hostname: string, port: number | null, entries: NoProxyEntry[]): boolean;
|
|
27
|
+
export interface EnvProxyConfig {
|
|
28
|
+
httpProxy?: string;
|
|
29
|
+
httpsProxy?: string;
|
|
30
|
+
noProxy?: string;
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* Pure routing decision used by EnvProxyDispatcher (exported for tests):
|
|
34
|
+
* returns the proxy URL to use for the given origin, or null for a direct connection.
|
|
35
|
+
*/
|
|
36
|
+
export declare function selectProxyForOrigin(origin: string | URL, config: EnvProxyConfig): string | null;
|
|
37
|
+
export interface EnvProxyDispatcherOptions extends EnvProxyConfig {
|
|
38
|
+
agentOptions?: Agent.Options;
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* Dispatcher that routes traffic through HTTP(S)_PROXY unless the target
|
|
42
|
+
* matches NO_PROXY. Mirrors undici's EnvHttpProxyAgent fallback semantics
|
|
43
|
+
* (https targets fall back to HTTP_PROXY when HTTPS_PROXY is unset) but
|
|
44
|
+
* with full NO_PROXY support (CIDR, suffixes, ports, wildcard).
|
|
45
|
+
*/
|
|
46
|
+
export declare class EnvProxyDispatcher extends Dispatcher {
|
|
47
|
+
private directAgent;
|
|
48
|
+
private httpAgent;
|
|
49
|
+
private httpsAgent;
|
|
50
|
+
private noProxyEntries;
|
|
51
|
+
private ownedAgents;
|
|
52
|
+
constructor(opts?: EnvProxyDispatcherOptions);
|
|
53
|
+
dispatch(options: Dispatcher.DispatchOptions, handler: Dispatcher.DispatchHandlers): boolean;
|
|
54
|
+
close(): Promise<void>;
|
|
55
|
+
destroy(): Promise<void>;
|
|
56
|
+
}
|
|
5
57
|
/**
|
|
6
|
-
*
|
|
7
|
-
* once at startup, before any outbound request.
|
|
58
|
+
* Configure global proxy for all fetch/undici-based traffic.
|
|
8
59
|
*
|
|
9
|
-
*
|
|
10
|
-
*
|
|
11
|
-
*
|
|
12
|
-
*
|
|
13
|
-
*
|
|
14
|
-
* 3. Neither: leaves the default dispatcher untouched (no behavior change).
|
|
60
|
+
* - If explicitProxyUrl is provided (--proxy), it takes precedence and is
|
|
61
|
+
* used for ALL traffic (NO_PROXY is intentionally not applied).
|
|
62
|
+
* - Otherwise, standard HTTP_PROXY / HTTPS_PROXY / NO_PROXY environment
|
|
63
|
+
* variables are honored with full NO_PROXY support (exact hosts, domain
|
|
64
|
+
* suffixes, wildcards, ":port" qualifiers, IPv4/IPv6 CIDR ranges).
|
|
15
65
|
*
|
|
16
|
-
*
|
|
66
|
+
* Works on any supported Node.js version without NODE_USE_ENV_PROXY.
|
|
17
67
|
*/
|
|
18
68
|
export declare function configureGlobalProxy(explicitProxyUrl?: string): boolean;
|
|
69
|
+
export declare function maskProxyUrl(url: string): string;
|
|
70
|
+
export declare function logGlobalDispatcherDebug(): void;
|
package/dist/src/utils/proxy.js
CHANGED
|
@@ -1,66 +1,351 @@
|
|
|
1
|
+
import { Agent, Dispatcher, ProxyAgent, getGlobalDispatcher, setGlobalDispatcher } from "undici";
|
|
2
|
+
const ENV_HTTP_PROXY = ["HTTP_PROXY", "http_proxy"];
|
|
3
|
+
const ENV_HTTPS_PROXY = ["HTTPS_PROXY", "https_proxy"];
|
|
4
|
+
const ENV_NO_PROXY = ["NO_PROXY", "no_proxy"];
|
|
1
5
|
/**
|
|
2
|
-
*
|
|
3
|
-
*
|
|
4
|
-
* Node's built-in env-proxy support (NODE_USE_ENV_PROXY / --use-env-proxy)
|
|
5
|
-
* only exists in Node >= v22.21.0 / v24.0.0. Installing an undici global
|
|
6
|
-
* dispatcher provides the same behavior on every supported Node (>= 20) and
|
|
7
|
-
* covers every fetch() issued in-process: the mcp-reverse SSE connector, its
|
|
8
|
-
* message POSTs, and the MCP SDK client transports (including EventSource,
|
|
9
|
-
* which delegates to globalThis.fetch).
|
|
6
|
+
* Whether proxy environment variables are present (NO_PROXY alone does not count).
|
|
10
7
|
*/
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
8
|
+
export function hasProxyEnv(env = process.env) {
|
|
9
|
+
return [...ENV_HTTP_PROXY, ...ENV_HTTPS_PROXY].some((key) => Boolean(env[key]));
|
|
10
|
+
}
|
|
11
|
+
/** Parse an IPv4 literal into a 32-bit number (using multiplication to avoid sign issues). */
|
|
12
|
+
function parseIpv4ToInt(ip) {
|
|
13
|
+
const m = /^(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})$/.exec(ip);
|
|
14
|
+
if (!m)
|
|
15
|
+
return null;
|
|
16
|
+
let result = 0;
|
|
17
|
+
for (let i = 1; i <= 4; i++) {
|
|
18
|
+
const octet = Number(m[i]);
|
|
19
|
+
if (octet > 255)
|
|
20
|
+
return null;
|
|
21
|
+
result = result * 256 + octet;
|
|
22
|
+
}
|
|
23
|
+
return result;
|
|
24
|
+
}
|
|
25
|
+
function matchIpv4Cidr(ip, base, bits) {
|
|
26
|
+
if (bits <= 0)
|
|
27
|
+
return true;
|
|
28
|
+
if (bits >= 32)
|
|
29
|
+
return ip === base;
|
|
30
|
+
const shift = 32 - bits;
|
|
31
|
+
return Math.floor(ip / 2 ** shift) === Math.floor(base / 2 ** shift);
|
|
32
|
+
}
|
|
33
|
+
/** Parse an IPv6 literal (with "::" compression and optional embedded IPv4 tail) into a 128-bit bigint. */
|
|
34
|
+
function parseIpv6ToBigInt(ipInput) {
|
|
35
|
+
let ip = ipInput;
|
|
36
|
+
const zoneIdx = ip.indexOf("%"); // strip zone id, e.g. fe80::1%eth0
|
|
37
|
+
if (zoneIdx >= 0)
|
|
38
|
+
ip = ip.slice(0, zoneIdx);
|
|
39
|
+
ip = ip.toLowerCase();
|
|
40
|
+
if (!/^[0-9a-f:.]+$/.test(ip))
|
|
41
|
+
return null;
|
|
42
|
+
const expandV4Tail = (groups) => {
|
|
43
|
+
const last = groups[groups.length - 1];
|
|
44
|
+
if (last && last.includes(".")) {
|
|
45
|
+
const v4 = parseIpv4ToInt(last);
|
|
46
|
+
if (v4 === null)
|
|
47
|
+
return null;
|
|
48
|
+
groups[groups.length - 1] = Math.floor(v4 / 65536).toString(16);
|
|
49
|
+
groups.push((v4 % 65536).toString(16));
|
|
50
|
+
}
|
|
51
|
+
return groups;
|
|
52
|
+
};
|
|
53
|
+
let groups;
|
|
54
|
+
if (ip.includes("::")) {
|
|
55
|
+
const halves = ip.split("::");
|
|
56
|
+
if (halves.length !== 2)
|
|
57
|
+
return null; // at most one "::"
|
|
58
|
+
const head = halves[0] ? halves[0].split(":") : [];
|
|
59
|
+
const tail = halves[1] ? halves[1].split(":") : [];
|
|
60
|
+
const expandedTail = expandV4Tail(tail);
|
|
61
|
+
if (expandedTail === null)
|
|
62
|
+
return null;
|
|
63
|
+
const missing = 8 - (head.length + expandedTail.length);
|
|
64
|
+
if (missing < 1)
|
|
65
|
+
return null;
|
|
66
|
+
groups = [...head, ...Array(missing).fill("0"), ...expandedTail];
|
|
67
|
+
}
|
|
68
|
+
else {
|
|
69
|
+
const expanded = expandV4Tail(ip.split(":"));
|
|
70
|
+
if (expanded === null)
|
|
71
|
+
return null;
|
|
72
|
+
groups = expanded;
|
|
73
|
+
}
|
|
74
|
+
if (groups.length !== 8)
|
|
75
|
+
return null;
|
|
76
|
+
let result = 0n;
|
|
77
|
+
for (const g of groups) {
|
|
78
|
+
if (!/^[0-9a-f]{1,4}$/.test(g))
|
|
79
|
+
return null;
|
|
80
|
+
result = (result << 16n) | BigInt(parseInt(g, 16));
|
|
81
|
+
}
|
|
82
|
+
return result;
|
|
83
|
+
}
|
|
84
|
+
function matchIpv6Cidr(ip, base, bits) {
|
|
85
|
+
if (bits <= 0)
|
|
86
|
+
return true;
|
|
87
|
+
if (bits >= 128)
|
|
88
|
+
return ip === base;
|
|
89
|
+
const shift = BigInt(128 - bits);
|
|
90
|
+
return ip >> shift === base >> shift;
|
|
91
|
+
}
|
|
92
|
+
function parsePort(value) {
|
|
93
|
+
if (!/^\d{1,5}$/.test(value))
|
|
94
|
+
return null;
|
|
95
|
+
const port = Number(value);
|
|
96
|
+
return port >= 0 && port <= 65535 ? port : null;
|
|
97
|
+
}
|
|
98
|
+
function makeEntry(hostInput, port) {
|
|
99
|
+
let host = hostInput.toLowerCase();
|
|
100
|
+
if (host.endsWith("."))
|
|
101
|
+
host = host.slice(0, -1); // strip FQDN trailing dot
|
|
102
|
+
if (host.includes("/")) {
|
|
103
|
+
let [base, bitsStr] = host.split("/", 2);
|
|
104
|
+
// Optional port after the prefix length: "10.0.0.0/8:8080"
|
|
105
|
+
if (bitsStr.includes(":")) {
|
|
106
|
+
const [bitsPart, portPart] = bitsStr.split(":", 2);
|
|
107
|
+
const parsed = parsePort(portPart);
|
|
108
|
+
if (parsed !== null) {
|
|
109
|
+
bitsStr = bitsPart;
|
|
110
|
+
port = port ?? parsed;
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
const bits = Number(bitsStr);
|
|
114
|
+
const v4 = parseIpv4ToInt(base);
|
|
115
|
+
if (v4 !== null && Number.isInteger(bits) && bits >= 0 && bits <= 32) {
|
|
116
|
+
return { kind: "cidr4", host, port, network: v4, bits };
|
|
117
|
+
}
|
|
118
|
+
const v6 = parseIpv6ToBigInt(base);
|
|
119
|
+
if (v6 !== null && Number.isInteger(bits) && bits >= 0 && bits <= 128) {
|
|
120
|
+
return { kind: "cidr6", host, port, network: v6, bits };
|
|
121
|
+
}
|
|
122
|
+
// Unparseable CIDR: never matches (fail closed toward proxying, like undici).
|
|
123
|
+
return { kind: "exact", host: "invalid", port };
|
|
124
|
+
}
|
|
125
|
+
if (host.startsWith("*."))
|
|
126
|
+
return { kind: "suffix", host: host.slice(2), port };
|
|
127
|
+
if (host.startsWith("."))
|
|
128
|
+
return { kind: "suffix", host: host.slice(1), port };
|
|
129
|
+
return { kind: "exact", host, port };
|
|
130
|
+
}
|
|
131
|
+
/**
|
|
132
|
+
* Parse a NO_PROXY value into matchable entries.
|
|
133
|
+
* Supported: "*", exact hosts, ".example.com"/"*.example.com" suffixes,
|
|
134
|
+
* bare domains (exact + subdomains, curl semantics), "host:port",
|
|
135
|
+
* IPv4/IPv6 literals and CIDR ranges ("10.0.0.0/8", "fd00::/8").
|
|
136
|
+
*/
|
|
137
|
+
export function parseNoProxy(value) {
|
|
138
|
+
if (!value)
|
|
139
|
+
return [];
|
|
140
|
+
const entries = [];
|
|
141
|
+
for (const raw of value.split(",")) {
|
|
142
|
+
const token0 = raw.trim();
|
|
143
|
+
if (!token0)
|
|
144
|
+
continue;
|
|
145
|
+
if (token0 === "*") {
|
|
146
|
+
entries.push({ kind: "wildcard", host: "*", port: null });
|
|
147
|
+
continue;
|
|
148
|
+
}
|
|
149
|
+
// Bracketed IPv6, optionally with port: "[::1]" / "[::1]:8080"
|
|
150
|
+
if (token0.startsWith("[")) {
|
|
151
|
+
const close = token0.indexOf("]");
|
|
152
|
+
if (close > 0) {
|
|
153
|
+
const inner = token0.slice(1, close);
|
|
154
|
+
const rest = token0.slice(close + 1);
|
|
155
|
+
const port = rest.startsWith(":") ? parsePort(rest.slice(1)) : null;
|
|
156
|
+
entries.push(makeEntry(inner, port));
|
|
157
|
+
continue;
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
// "host:port" — only when there is exactly one colon (otherwise it is IPv6)
|
|
161
|
+
let host = token0;
|
|
162
|
+
let port = null;
|
|
163
|
+
if (!token0.includes("/")) {
|
|
164
|
+
const colonCount = (token0.match(/:/g) || []).length;
|
|
165
|
+
if (colonCount === 1) {
|
|
166
|
+
const [h, p] = token0.split(":");
|
|
167
|
+
const parsed = parsePort(p);
|
|
168
|
+
if (parsed !== null) {
|
|
169
|
+
host = h;
|
|
170
|
+
port = parsed;
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
entries.push(makeEntry(host, port));
|
|
175
|
+
}
|
|
176
|
+
return entries;
|
|
177
|
+
}
|
|
178
|
+
function isIpLiteral(host) {
|
|
179
|
+
return parseIpv4ToInt(host) !== null || host.includes(":");
|
|
180
|
+
}
|
|
181
|
+
/** Whether a target host:port matches any NO_PROXY entry (i.e. should bypass the proxy). */
|
|
182
|
+
export function matchesNoProxy(hostname, port, entries) {
|
|
183
|
+
if (!hostname)
|
|
184
|
+
return false;
|
|
185
|
+
let host = hostname.toLowerCase();
|
|
186
|
+
if (host.startsWith("[") && host.endsWith("]"))
|
|
187
|
+
host = host.slice(1, -1);
|
|
188
|
+
if (host.endsWith("."))
|
|
189
|
+
host = host.slice(0, -1);
|
|
190
|
+
for (const entry of entries) {
|
|
191
|
+
if (entry.kind === "wildcard")
|
|
192
|
+
return true;
|
|
193
|
+
if (entry.port !== null && entry.port !== port)
|
|
194
|
+
continue;
|
|
195
|
+
switch (entry.kind) {
|
|
196
|
+
case "exact":
|
|
197
|
+
if (host === entry.host)
|
|
198
|
+
return true;
|
|
199
|
+
// Bare-domain entries also cover subdomains (curl/wget semantics).
|
|
200
|
+
if (!isIpLiteral(entry.host) && host.endsWith(`.${entry.host}`))
|
|
201
|
+
return true;
|
|
202
|
+
break;
|
|
203
|
+
case "suffix":
|
|
204
|
+
if (host === entry.host || host.endsWith(`.${entry.host}`))
|
|
205
|
+
return true;
|
|
206
|
+
break;
|
|
207
|
+
case "cidr4": {
|
|
208
|
+
const v4 = parseIpv4ToInt(host);
|
|
209
|
+
if (v4 !== null && matchIpv4Cidr(v4, entry.network, entry.bits))
|
|
210
|
+
return true;
|
|
211
|
+
break;
|
|
212
|
+
}
|
|
213
|
+
case "cidr6": {
|
|
214
|
+
const v6 = parseIpv6ToBigInt(host);
|
|
215
|
+
if (v6 !== null && matchIpv6Cidr(v6, entry.network, entry.bits))
|
|
216
|
+
return true;
|
|
217
|
+
break;
|
|
218
|
+
}
|
|
219
|
+
}
|
|
220
|
+
}
|
|
221
|
+
return false;
|
|
222
|
+
}
|
|
223
|
+
/**
|
|
224
|
+
* Pure routing decision used by EnvProxyDispatcher (exported for tests):
|
|
225
|
+
* returns the proxy URL to use for the given origin, or null for a direct connection.
|
|
226
|
+
*/
|
|
227
|
+
export function selectProxyForOrigin(origin, config) {
|
|
228
|
+
let url;
|
|
14
229
|
try {
|
|
15
|
-
|
|
16
|
-
if (url.username)
|
|
17
|
-
url.username = "***";
|
|
18
|
-
if (url.password)
|
|
19
|
-
url.password = "***";
|
|
20
|
-
return url.toString();
|
|
230
|
+
url = typeof origin === "string" ? new URL(origin) : origin;
|
|
21
231
|
}
|
|
22
232
|
catch {
|
|
23
|
-
return
|
|
233
|
+
return null;
|
|
24
234
|
}
|
|
235
|
+
const protocol = url.protocol.toLowerCase();
|
|
236
|
+
if (protocol !== "http:" && protocol !== "https:")
|
|
237
|
+
return null;
|
|
238
|
+
const port = url.port ? Number(url.port) : protocol === "https:" ? 443 : 80;
|
|
239
|
+
if (matchesNoProxy(url.hostname, port, parseNoProxy(config.noProxy)))
|
|
240
|
+
return null;
|
|
241
|
+
if (protocol === "https:")
|
|
242
|
+
return config.httpsProxy ?? config.httpProxy ?? null;
|
|
243
|
+
return config.httpProxy ?? null;
|
|
25
244
|
}
|
|
26
|
-
/**
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
245
|
+
/**
|
|
246
|
+
* Dispatcher that routes traffic through HTTP(S)_PROXY unless the target
|
|
247
|
+
* matches NO_PROXY. Mirrors undici's EnvHttpProxyAgent fallback semantics
|
|
248
|
+
* (https targets fall back to HTTP_PROXY when HTTPS_PROXY is unset) but
|
|
249
|
+
* with full NO_PROXY support (CIDR, suffixes, ports, wildcard).
|
|
250
|
+
*/
|
|
251
|
+
export class EnvProxyDispatcher extends Dispatcher {
|
|
252
|
+
directAgent;
|
|
253
|
+
httpAgent;
|
|
254
|
+
httpsAgent;
|
|
255
|
+
noProxyEntries;
|
|
256
|
+
ownedAgents;
|
|
257
|
+
constructor(opts = {}) {
|
|
258
|
+
super();
|
|
259
|
+
const agentOpts = opts.agentOptions ?? {};
|
|
260
|
+
this.directAgent = new Agent(agentOpts);
|
|
261
|
+
this.ownedAgents = [this.directAgent];
|
|
262
|
+
this.noProxyEntries = parseNoProxy(opts.noProxy);
|
|
263
|
+
const mkProxy = (uri) => {
|
|
264
|
+
const agent = new ProxyAgent({ ...agentOpts, uri });
|
|
265
|
+
this.ownedAgents.push(agent);
|
|
266
|
+
return agent;
|
|
267
|
+
};
|
|
268
|
+
this.httpAgent = opts.httpProxy ? mkProxy(opts.httpProxy) : this.directAgent;
|
|
269
|
+
this.httpsAgent = opts.httpsProxy ? mkProxy(opts.httpsProxy) : this.httpAgent;
|
|
270
|
+
}
|
|
271
|
+
dispatch(options, handler) {
|
|
272
|
+
let agent = this.directAgent;
|
|
273
|
+
try {
|
|
274
|
+
const url = new URL(options.origin);
|
|
275
|
+
const protocol = url.protocol.toLowerCase();
|
|
276
|
+
const port = url.port ? Number(url.port) : protocol === "https:" ? 443 : 80;
|
|
277
|
+
if (!matchesNoProxy(url.hostname, port, this.noProxyEntries)) {
|
|
278
|
+
agent = protocol === "https:" ? this.httpsAgent : this.httpAgent;
|
|
279
|
+
}
|
|
280
|
+
}
|
|
281
|
+
catch {
|
|
282
|
+
// Unparseable origin: fall back to direct.
|
|
283
|
+
}
|
|
284
|
+
return agent.dispatch(options, handler);
|
|
285
|
+
}
|
|
286
|
+
async close() {
|
|
287
|
+
await Promise.all(this.ownedAgents.map((agent) => agent.close()));
|
|
288
|
+
}
|
|
289
|
+
async destroy() {
|
|
290
|
+
await Promise.all(this.ownedAgents.map((agent) => agent.destroy()));
|
|
291
|
+
}
|
|
32
292
|
}
|
|
293
|
+
// ============================================================
|
|
294
|
+
// Global installation
|
|
295
|
+
// ============================================================
|
|
33
296
|
/**
|
|
34
|
-
*
|
|
35
|
-
* once at startup, before any outbound request.
|
|
297
|
+
* Configure global proxy for all fetch/undici-based traffic.
|
|
36
298
|
*
|
|
37
|
-
*
|
|
38
|
-
*
|
|
39
|
-
*
|
|
40
|
-
*
|
|
41
|
-
*
|
|
42
|
-
* 3. Neither: leaves the default dispatcher untouched (no behavior change).
|
|
299
|
+
* - If explicitProxyUrl is provided (--proxy), it takes precedence and is
|
|
300
|
+
* used for ALL traffic (NO_PROXY is intentionally not applied).
|
|
301
|
+
* - Otherwise, standard HTTP_PROXY / HTTPS_PROXY / NO_PROXY environment
|
|
302
|
+
* variables are honored with full NO_PROXY support (exact hosts, domain
|
|
303
|
+
* suffixes, wildcards, ":port" qualifiers, IPv4/IPv6 CIDR ranges).
|
|
43
304
|
*
|
|
44
|
-
*
|
|
305
|
+
* Works on any supported Node.js version without NODE_USE_ENV_PROXY.
|
|
45
306
|
*/
|
|
46
307
|
export function configureGlobalProxy(explicitProxyUrl) {
|
|
47
|
-
|
|
48
|
-
|
|
308
|
+
if (explicitProxyUrl) {
|
|
309
|
+
try {
|
|
49
310
|
setGlobalDispatcher(new ProxyAgent(explicitProxyUrl));
|
|
50
|
-
console.error(`[staff-mcp] Outbound proxy: ${
|
|
51
|
-
`(applies to all requests; NO_PROXY is not applied for --proxy)`);
|
|
311
|
+
console.error(`[staff-mcp] Outbound proxy: using ${explicitProxyUrl} for all traffic (NO_PROXY not applied)`);
|
|
52
312
|
return true;
|
|
53
313
|
}
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
return true;
|
|
314
|
+
catch (err) {
|
|
315
|
+
console.error(`[staff-mcp] Outbound proxy: failed to configure explicit proxy "${explicitProxyUrl}": ${err?.message ?? err}`);
|
|
316
|
+
return false;
|
|
58
317
|
}
|
|
59
318
|
}
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
319
|
+
const httpProxy = process.env.HTTP_PROXY || process.env.http_proxy;
|
|
320
|
+
const httpsProxy = process.env.HTTPS_PROXY || process.env.https_proxy;
|
|
321
|
+
const noProxy = process.env.NO_PROXY || process.env.no_proxy;
|
|
322
|
+
if (httpProxy || httpsProxy) {
|
|
323
|
+
setGlobalDispatcher(new EnvProxyDispatcher({ httpProxy, httpsProxy, noProxy }));
|
|
324
|
+
const proxiesFound = [httpProxy && "HTTP_PROXY", httpsProxy && "HTTPS_PROXY"].filter(Boolean).join("/");
|
|
325
|
+
console.error(`[staff-mcp] Outbound proxy: honoring ${proxiesFound}${noProxy ? "/NO_PROXY" : ""} environment variables`);
|
|
326
|
+
return true;
|
|
63
327
|
}
|
|
64
328
|
return false;
|
|
65
329
|
}
|
|
330
|
+
export function maskProxyUrl(url) {
|
|
331
|
+
try {
|
|
332
|
+
const u = new URL(url);
|
|
333
|
+
if (u.username || u.password) {
|
|
334
|
+
u.username = "***";
|
|
335
|
+
u.password = "***";
|
|
336
|
+
}
|
|
337
|
+
return u.toString();
|
|
338
|
+
}
|
|
339
|
+
catch {
|
|
340
|
+
return "<invalid proxy URL>";
|
|
341
|
+
}
|
|
342
|
+
}
|
|
343
|
+
export function logGlobalDispatcherDebug() {
|
|
344
|
+
const d = getGlobalDispatcher();
|
|
345
|
+
const name = d?.constructor?.name ?? "unknown";
|
|
346
|
+
const proxyKeys = Object.getOwnPropertySymbols(d)
|
|
347
|
+
.map((s) => s.toString())
|
|
348
|
+
.filter((s) => s.includes("proxy") || s.includes("Proxy"));
|
|
349
|
+
console.error(`[staff-mcp][debug] global dispatcher: ${name} symbols: ${proxyKeys.join(", ") || "none"}`);
|
|
350
|
+
}
|
|
66
351
|
//# sourceMappingURL=proxy.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"proxy.js","sourceRoot":"","sources":["../../../src/utils/proxy.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AACH,OAAO,EAAE,iBAAiB,EAAE,UAAU,EAAE,mBAAmB,EAAE,MAAM,QAAQ,CAAC;AAE5E,4DAA4D;AAC5D,MAAM,UAAU,YAAY,CAAC,QAAgB;IACzC,IAAI,CAAC;QACD,MAAM,GAAG,GAAG,IAAI,GAAG,CAAC,QAAQ,CAAC,CAAC;QAC9B,IAAI,GAAG,CAAC,QAAQ;YAAE,GAAG,CAAC,QAAQ,GAAG,KAAK,CAAC;QACvC,IAAI,GAAG,CAAC,QAAQ;YAAE,GAAG,CAAC,QAAQ,GAAG,KAAK,CAAC;QACvC,OAAO,GAAG,CAAC,QAAQ,EAAE,CAAC;IAC1B,CAAC;IAAC,MAAM,CAAC;QACL,OAAO,qBAAqB,CAAC;IACjC,CAAC;AACL,CAAC;AAED,2DAA2D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ACH,CAAC;AAED,MAAM,UAAU,wBAAwB;IACtC,MAAM,CAAC,GAAG,mBAAmB,EAG5B,CAAC;IACF,MAAM,IAAI,GAAG,CAAC,EAAE,WAAW,EAAE,IAAI,IAAI,SAAS,CAAC;IAC/C,MAAM,SAAS,GAAG,MAAM,CAAC,qBAAqB,CAAC,CAAC,CAAC;SAC9C,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,QAAQ,EAAE,CAAC;SACxB,MAAM,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,QAAQ,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC,QAAQ,CAAC,OAAO,CAAC,CAAC,CAAC;IAC7D,OAAO,CAAC,KAAK,CAAC,yCAAyC,IAAI,aAAa,SAAS,CAAC,IAAI,CAAC,IAAI,CAAC,IAAI,MAAM,EAAE,CAAC,CAAC;AAC5G,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,156 @@
|
|
|
1
|
+
import assert from "node:assert/strict";
|
|
2
|
+
import { test, after } from "node:test";
|
|
3
|
+
import http from "node:http";
|
|
4
|
+
import net from "node:net";
|
|
5
|
+
import { fetch } from "undici";
|
|
6
|
+
import { EnvProxyDispatcher, matchesNoProxy, parseNoProxy, selectProxyForOrigin, } from "../src/utils/proxy.js";
|
|
7
|
+
// ------------------------------------------------------------
|
|
8
|
+
// Pure matcher tests
|
|
9
|
+
// ------------------------------------------------------------
|
|
10
|
+
function m(noProxy, host, port = 80) {
|
|
11
|
+
return matchesNoProxy(host, port, parseNoProxy(noProxy));
|
|
12
|
+
}
|
|
13
|
+
test("NO_PROXY wildcard bypasses everything", () => {
|
|
14
|
+
assert.equal(m("*", "anything.example.com", 443), true);
|
|
15
|
+
assert.equal(m("*,proxy.internal", "proxy.internal"), true);
|
|
16
|
+
});
|
|
17
|
+
test("NO_PROXY exact hosts and case-insensitivity", () => {
|
|
18
|
+
assert.equal(m("172.25.44.201", "172.25.44.201"), true);
|
|
19
|
+
assert.equal(m("172.25.44.201", "172.25.44.202"), false);
|
|
20
|
+
assert.equal(m("EXAMPLE.com", "example.COM"), true);
|
|
21
|
+
assert.equal(m("example.com.", "example.com"), true); // FQDN trailing dot
|
|
22
|
+
assert.equal(m("example.com", "example.com."), true);
|
|
23
|
+
});
|
|
24
|
+
test("NO_PROXY domain suffixes (leading dot, star, bare domain)", () => {
|
|
25
|
+
assert.equal(m(".example.com", "www.example.com"), true);
|
|
26
|
+
assert.equal(m(".example.com", "example.com"), true);
|
|
27
|
+
assert.equal(m("*.example.com", "a.b.example.com"), true);
|
|
28
|
+
// bare domain covers subdomains too (curl/wget semantics)
|
|
29
|
+
assert.equal(m("example.com", "www.example.com"), true);
|
|
30
|
+
assert.equal(m("example.com", "notexample.com"), false);
|
|
31
|
+
assert.equal(m("ample.com", "example.com"), false);
|
|
32
|
+
});
|
|
33
|
+
test("NO_PROXY port qualifier restricts the entry to that port", () => {
|
|
34
|
+
assert.equal(m("example.com:8080", "example.com", 8080), true);
|
|
35
|
+
assert.equal(m("example.com:8080", "example.com", 80), false);
|
|
36
|
+
assert.equal(m("10.0.0.0/8:8080", "10.1.2.3", 8080), true);
|
|
37
|
+
assert.equal(m("10.0.0.0/8:8080", "10.1.2.3", 80), false);
|
|
38
|
+
});
|
|
39
|
+
test("NO_PROXY IPv4 CIDR ranges", () => {
|
|
40
|
+
// the corporate container case: 172.16.0.0/12 covers 172.16.0.0 - 172.31.255.255
|
|
41
|
+
assert.equal(m("172.16.0.0/12", "172.25.44.201"), true);
|
|
42
|
+
assert.equal(m("172.16.0.0/12", "172.31.255.254"), true);
|
|
43
|
+
assert.equal(m("172.16.0.0/12", "172.32.0.1"), false);
|
|
44
|
+
assert.equal(m("172.16.0.0/12", "10.0.0.1"), false);
|
|
45
|
+
assert.equal(m("10.0.0.0/8", "10.3.0.4"), true);
|
|
46
|
+
assert.equal(m("192.168.0.0/16", "192.168.1.1"), true);
|
|
47
|
+
assert.equal(m("192.168.0.0/16", "192.167.1.1"), false);
|
|
48
|
+
// boundary prefix lengths
|
|
49
|
+
assert.equal(m("0.0.0.0/0", "203.0.113.9"), true);
|
|
50
|
+
assert.equal(m("10.1.2.3/32", "10.1.2.3"), true);
|
|
51
|
+
assert.equal(m("10.1.2.3/32", "10.1.2.4"), false);
|
|
52
|
+
// hostnames never match IP CIDRs
|
|
53
|
+
assert.equal(m("10.0.0.0/8", "host.example.com"), false);
|
|
54
|
+
});
|
|
55
|
+
test("NO_PROXY IPv6 literals and CIDR ranges", () => {
|
|
56
|
+
assert.equal(m("::1", "::1"), true);
|
|
57
|
+
assert.equal(m("::1", "[::1]"), true);
|
|
58
|
+
assert.equal(m("[::1]", "::1"), true);
|
|
59
|
+
assert.equal(m("fd00::/8", "fd12::3456"), true);
|
|
60
|
+
assert.equal(m("fd00::/8", "fe80::1"), false);
|
|
61
|
+
assert.equal(m("fe80::/10", "fe80::1%eth0"), true); // zone id tolerated
|
|
62
|
+
// embedded IPv4 tail
|
|
63
|
+
assert.equal(m("::ffff:10.0.0.0/104", "::ffff:10.1.2.3"), true);
|
|
64
|
+
});
|
|
65
|
+
test("NO_PROXY invalid entries never match and never throw", () => {
|
|
66
|
+
assert.equal(m("10.0.0.0/33", "10.1.2.3"), false);
|
|
67
|
+
assert.equal(m("garbage///", "garbage"), false);
|
|
68
|
+
assert.equal(m("", "anything"), false);
|
|
69
|
+
assert.doesNotThrow(() => parseNoProxy(":::,,,[/8,"));
|
|
70
|
+
});
|
|
71
|
+
test("selectProxyForOrigin routing decisions", () => {
|
|
72
|
+
const cfg = { httpProxy: "http://proxy:10808", httpsProxy: "http://sproxy:10809" };
|
|
73
|
+
// CIDR bypass — the exact regression scenario from the field report
|
|
74
|
+
assert.equal(selectProxyForOrigin("http://172.25.44.201/api/mcp/reverse/sse", {
|
|
75
|
+
httpProxy: "http://172.25.44.201:10808",
|
|
76
|
+
noProxy: "localhost,127.0.0.1,192.168.0.0/16,172.16.0.0/12,10.0.0.0/8",
|
|
77
|
+
}), null);
|
|
78
|
+
// not covered by NO_PROXY → use the per-protocol proxy
|
|
79
|
+
assert.equal(selectProxyForOrigin("http://8.8.8.8/x", { ...cfg, noProxy: "172.16.0.0/12" }), "http://proxy:10808");
|
|
80
|
+
assert.equal(selectProxyForOrigin("https://8.8.8.8/x", { ...cfg, noProxy: "" }), "http://sproxy:10809");
|
|
81
|
+
// https falls back to HTTP_PROXY when HTTPS_PROXY is unset (undici semantics)
|
|
82
|
+
assert.equal(selectProxyForOrigin("https://8.8.8.8/x", { httpProxy: "http://proxy:10808" }), "http://proxy:10808");
|
|
83
|
+
// http never uses HTTPS_PROXY
|
|
84
|
+
assert.equal(selectProxyForOrigin("http://8.8.8.8/x", { httpsProxy: "http://sproxy:10809" }), null);
|
|
85
|
+
// default ports participate in port-qualified NO_PROXY entries
|
|
86
|
+
assert.equal(selectProxyForOrigin("http://example.com/path", { httpProxy: "http://p:1", noProxy: "example.com:80" }), null);
|
|
87
|
+
assert.equal(selectProxyForOrigin("http://example.com:8080/path", { httpProxy: "http://p:1", noProxy: "example.com:80" }), "http://p:1");
|
|
88
|
+
// non-http protocols and garbage go direct
|
|
89
|
+
assert.equal(selectProxyForOrigin("ws://example.com/x", cfg), null);
|
|
90
|
+
assert.equal(selectProxyForOrigin("not a url", cfg), null);
|
|
91
|
+
});
|
|
92
|
+
async function startTargetServer() {
|
|
93
|
+
const server = http.createServer((req, res) => {
|
|
94
|
+
res.writeHead(200, { "content-type": "text/plain" });
|
|
95
|
+
res.end("target-ok");
|
|
96
|
+
});
|
|
97
|
+
await new Promise((resolve) => server.listen(0, "127.0.0.1", resolve));
|
|
98
|
+
const { port } = server.address();
|
|
99
|
+
return {
|
|
100
|
+
url: `http://127.0.0.1:${port}`,
|
|
101
|
+
close: () => new Promise((resolve) => server.close(() => resolve())),
|
|
102
|
+
};
|
|
103
|
+
}
|
|
104
|
+
/** Minimal HTTP proxy that handles CONNECT tunnels and counts them. */
|
|
105
|
+
async function startConnectProxy() {
|
|
106
|
+
let hits = 0;
|
|
107
|
+
const server = http.createServer((req, res) => {
|
|
108
|
+
res.writeHead(418);
|
|
109
|
+
res.end("unexpected plain proxy request");
|
|
110
|
+
});
|
|
111
|
+
server.on("connect", (req, socket, head) => {
|
|
112
|
+
hits++;
|
|
113
|
+
const [host, portStr] = (req.url ?? "").split(":");
|
|
114
|
+
const upstream = net.connect(Number(portStr), host, () => {
|
|
115
|
+
socket.write("HTTP/1.1 200 Connection Established\r\n\r\n");
|
|
116
|
+
if (head?.length)
|
|
117
|
+
upstream.write(head);
|
|
118
|
+
upstream.pipe(socket);
|
|
119
|
+
socket.pipe(upstream);
|
|
120
|
+
});
|
|
121
|
+
upstream.on("error", () => socket.end());
|
|
122
|
+
socket.on("error", () => upstream.destroy());
|
|
123
|
+
});
|
|
124
|
+
await new Promise((resolve) => server.listen(0, "127.0.0.1", resolve));
|
|
125
|
+
const { port } = server.address();
|
|
126
|
+
return {
|
|
127
|
+
url: `http://127.0.0.1:${port}`,
|
|
128
|
+
hits: () => hits,
|
|
129
|
+
close: () => new Promise((resolve) => server.close(() => resolve())),
|
|
130
|
+
};
|
|
131
|
+
}
|
|
132
|
+
const cleanups = [];
|
|
133
|
+
after(async () => {
|
|
134
|
+
for (const cleanup of cleanups.splice(0))
|
|
135
|
+
await cleanup();
|
|
136
|
+
});
|
|
137
|
+
test("EnvProxyDispatcher bypasses NO_PROXY CIDR targets, proxies the rest", async () => {
|
|
138
|
+
const target = await startTargetServer();
|
|
139
|
+
const proxy = await startConnectProxy();
|
|
140
|
+
cleanups.push(target.close, proxy.close);
|
|
141
|
+
// 1) target inside NO_PROXY range → direct, proxy untouched
|
|
142
|
+
const bypass = new EnvProxyDispatcher({ httpProxy: proxy.url, noProxy: "127.0.0.0/8" });
|
|
143
|
+
cleanups.push(() => bypass.close());
|
|
144
|
+
const res1 = await fetch(`${target.url}/ping`, { dispatcher: bypass });
|
|
145
|
+
assert.equal(res1.status, 200);
|
|
146
|
+
assert.equal(await res1.text(), "target-ok");
|
|
147
|
+
assert.equal(proxy.hits(), 0, "proxy must not be consulted for NO_PROXY targets");
|
|
148
|
+
// 2) target outside NO_PROXY range → CONNECT through the proxy
|
|
149
|
+
const proxied = new EnvProxyDispatcher({ httpProxy: proxy.url, noProxy: "10.0.0.0/8" });
|
|
150
|
+
cleanups.push(() => proxied.close());
|
|
151
|
+
const res2 = await fetch(`${target.url}/ping`, { dispatcher: proxied });
|
|
152
|
+
assert.equal(res2.status, 200);
|
|
153
|
+
assert.equal(await res2.text(), "target-ok");
|
|
154
|
+
assert.ok(proxy.hits() >= 1, "request should have been tunneled through the proxy");
|
|
155
|
+
});
|
|
156
|
+
//# sourceMappingURL=proxy-no-proxy.test.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"proxy-no-proxy.test.js","sourceRoot":"","sources":["../../tests/proxy-no-proxy.test.ts"],"names":[],"mappings":"AAAA,OAAO,MAAM,MAAM,oBAAoB,CAAC;AACxC,OAAO,EAAE,IAAI,EAAE,KAAK,EAAE,MAAM,WAAW,CAAC;AACxC,OAAO,IAAI,MAAM,WAAW,CAAC;AAC7B,OAAO,GAAG,MAAM,UAAU,CAAC;AAE3B,OAAO,EAAE,KAAK,EAAE,MAAM,QAAQ,CAAC;AAC/B,OAAO,EACL,kBAAkB,EAClB,cAAc,EACd,YAAY,EACZ,oBAAoB,GACrB,MAAM,uBAAuB,CAAC;AAE/B,+DAA+D;AAC/D,sBAAsB;AACtB,+DAA+D;AAE/D,SAAS,CAAC,CAAC,OAAe,EAAE,IAAY,EAAE,OAAsB,EAAE;IAChE,OAAO,cAAc,CAAC,IAAI,EAAE,IAAI,EAAE,YAAY,CAAC,OAAO,CAAC,CAAC,CAAC;AAC3D,CAAC;AAED,IAAI,CAAC,uCAAuC,EAAE,GAAG,EAAE;IACjD,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC,GAAG,EAAE,sBAAsB,EAAE,GAAG,CAAC,E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,CAAC,MAAM,IAAI,CAAC,IAAI,EAAE,EAAE,WAAW,CAAC,CAAC;IAC7C,MAAM,CAAC,KAAK,CAAC,KAAK,CAAC,IAAI,EAAE,EAAE,CAAC,EAAE,kDAAkD,CAAC,CAAC;IAElF,+DAA+D;IAC/D,MAAM,OAAO,GAAG,IAAI,kBAAkB,CAAC,EAAE,SAAS,EAAE,KAAK,CAAC,GAAG,EAAE,OAAO,EAAE,YAAY,EAAE,CAAC,CAAC;IACxF,QAAQ,CAAC,IAAI,CAAC,GAAG,EAAE,CAAC,OAAO,CAAC,KAAK,EAAE,CAAC,CAAC;IACrC,MAAM,IAAI,GAAG,MAAM,KAAK,CAAC,GAAG,MAAM,CAAC,GAAG,OAAO,EAAE,EAAE,UAAU,EAAE,OAAO,EAAE,CAAC,CAAC;IACxE,MAAM,CAAC,KAAK,CAAC,IAAI,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;IAC/B,MAAM,CAAC,KAAK,CAAC,MAAM,IAAI,CAAC,IAAI,EAAE,EAAE,WAAW,CAAC,CAAC;IAC7C,MAAM,CAAC,EAAE,CAAC,KAAK,CAAC,IAAI,EAAE,IAAI,CAAC,EAAE,qDAAqD,CAAC,CAAC;AACtF,CAAC,CAAC,CAAC"}
|
package/dist/tests/proxy.test.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import assert from "node:assert/strict";
|
|
2
2
|
import { test } from "node:test";
|
|
3
|
-
import { Agent,
|
|
4
|
-
import { configureGlobalProxy, hasProxyEnv, maskProxyUrl, } from "../src/utils/proxy.js";
|
|
3
|
+
import { Agent, ProxyAgent, getGlobalDispatcher, setGlobalDispatcher, } from "undici";
|
|
4
|
+
import { EnvProxyDispatcher, configureGlobalProxy, hasProxyEnv, maskProxyUrl, } from "../src/utils/proxy.js";
|
|
5
5
|
const PROXY_ENV_KEYS = [
|
|
6
6
|
"HTTP_PROXY",
|
|
7
7
|
"http_proxy",
|
|
@@ -52,11 +52,11 @@ test("explicit --proxy installs a ProxyAgent for all traffic", () => withCleanPr
|
|
|
52
52
|
restoreDefaultDispatcher();
|
|
53
53
|
}
|
|
54
54
|
}));
|
|
55
|
-
test("proxy env vars install an
|
|
55
|
+
test("proxy env vars install an EnvProxyDispatcher", () => withCleanProxyEnv(() => {
|
|
56
56
|
process.env.HTTPS_PROXY = "http://127.0.0.1:8080";
|
|
57
57
|
try {
|
|
58
58
|
assert.equal(configureGlobalProxy(), true);
|
|
59
|
-
assert.ok(getGlobalDispatcher() instanceof
|
|
59
|
+
assert.ok(getGlobalDispatcher() instanceof EnvProxyDispatcher);
|
|
60
60
|
}
|
|
61
61
|
finally {
|
|
62
62
|
restoreDefaultDispatcher();
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"proxy.test.js","sourceRoot":"","sources":["../../tests/proxy.test.ts"],"names":[],"mappings":"AAAA,OAAO,MAAM,MAAM,oBAAoB,CAAC;AACxC,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AACjC,OAAO,EACH,KAAK,EACL,
|
|
1
|
+
{"version":3,"file":"proxy.test.js","sourceRoot":"","sources":["../../tests/proxy.test.ts"],"names":[],"mappings":"AAAA,OAAO,MAAM,MAAM,oBAAoB,CAAC;AACxC,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AACjC,OAAO,EACH,KAAK,EACL,UAAU,EACV,mBAAmB,EACnB,mBAAmB,GACtB,MAAM,QAAQ,CAAC;AAChB,OAAO,EACH,kBAAkB,EAClB,oBAAoB,EACpB,WAAW,EACX,YAAY,GACf,MAAM,uBAAuB,CAAC;AAE/B,MAAM,cAAc,GAAG;IACnB,YAAY;IACZ,YAAY;IACZ,aAAa;IACb,aAAa;IACb,UAAU;IACV,UAAU;CACJ,CAAC;AAEX,yEAAyE;AACzE,SAAS,iBAAiB,CAAI,EAAW;IACrC,MAAM,KAAK,GAAG,IAAI,GAAG,EAA8B,CAAC;IACpD,KAAK,MAAM,GAAG,IAAI,cAAc,EAAE,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