@pnpm/network.fetch 1100.0.3 → 1100.0.5
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/lib/dispatcher.js +42 -3
- package/package.json +5 -5
package/lib/dispatcher.js
CHANGED
|
@@ -23,7 +23,44 @@ setGlobalDispatcher(new Agent({
|
|
|
23
23
|
connect: {
|
|
24
24
|
autoSelectFamily: true,
|
|
25
25
|
},
|
|
26
|
-
}));
|
|
26
|
+
}).compose(stripSecFetchHeaders));
|
|
27
|
+
// undici's fetch() automatically adds sec-fetch-* headers (e.g. sec-fetch-mode: cors)
|
|
28
|
+
// per the Fetch spec. Some registries like Azure DevOps Artifacts interpret these as
|
|
29
|
+
// browser requests and reject them with HTTP 400. Since pnpm is a CLI tool, these
|
|
30
|
+
// headers serve no purpose and must be stripped.
|
|
31
|
+
// See https://github.com/pnpm/pnpm/issues/11572
|
|
32
|
+
function stripSecFetchHeaders(dispatch) {
|
|
33
|
+
return (opts, handler) => {
|
|
34
|
+
if (opts.headers) {
|
|
35
|
+
if (Array.isArray(opts.headers)) {
|
|
36
|
+
// Flat array format: [key1, val1, key2, val2, ...]
|
|
37
|
+
const filtered = [];
|
|
38
|
+
for (let i = 0; i < opts.headers.length; i += 2) {
|
|
39
|
+
if (!opts.headers[i].toLowerCase().startsWith('sec-fetch-')) {
|
|
40
|
+
filtered.push(opts.headers[i], opts.headers[i + 1]);
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
opts = { ...opts, headers: filtered };
|
|
44
|
+
}
|
|
45
|
+
else if (typeof opts.headers === 'object') {
|
|
46
|
+
// undici also accepts an iterable of [key, value] pairs (e.g. a Map or
|
|
47
|
+
// web Headers). Use that iterator when present; otherwise fall back to
|
|
48
|
+
// Object.entries for plain IncomingHttpHeaders objects.
|
|
49
|
+
const entries = Symbol.iterator in opts.headers
|
|
50
|
+
? opts.headers
|
|
51
|
+
: Object.entries(opts.headers);
|
|
52
|
+
const headers = {};
|
|
53
|
+
for (const [key, value] of entries) {
|
|
54
|
+
if (!key.toLowerCase().startsWith('sec-fetch-')) {
|
|
55
|
+
headers[key] = value;
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
opts = { ...opts, headers };
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
return dispatch(opts, handler);
|
|
62
|
+
};
|
|
63
|
+
}
|
|
27
64
|
const DISPATCHER_CACHE = new LRUCache({
|
|
28
65
|
max: 50,
|
|
29
66
|
dispose: (dispatcher) => {
|
|
@@ -130,6 +167,7 @@ function getProxyDispatcher(parsedUri, opts) {
|
|
|
130
167
|
else {
|
|
131
168
|
dispatcher = createHttpProxyDispatcher(proxyUrl, isHttps, opts, { ca, cert, key: certKey });
|
|
132
169
|
}
|
|
170
|
+
dispatcher = dispatcher.compose(stripSecFetchHeaders);
|
|
133
171
|
DISPATCHER_CACHE.set(key, dispatcher);
|
|
134
172
|
return dispatcher;
|
|
135
173
|
}
|
|
@@ -247,8 +285,9 @@ function getNonProxyDispatcher(parsedUri, opts) {
|
|
|
247
285
|
localAddress: opts.localAddress,
|
|
248
286
|
},
|
|
249
287
|
});
|
|
250
|
-
|
|
251
|
-
|
|
288
|
+
const dispatcher = agent.compose(stripSecFetchHeaders);
|
|
289
|
+
DISPATCHER_CACHE.set(key, dispatcher);
|
|
290
|
+
return dispatcher;
|
|
252
291
|
}
|
|
253
292
|
function checkNoProxy(parsedUri, opts) {
|
|
254
293
|
const host = parsedUri.hostname
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@pnpm/network.fetch",
|
|
3
|
-
"version": "1100.0.
|
|
3
|
+
"version": "1100.0.5",
|
|
4
4
|
"description": "Native fetch with retries",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"pnpm",
|
|
@@ -32,9 +32,9 @@
|
|
|
32
32
|
"socks": "^2.8.1",
|
|
33
33
|
"undici": "^7.2.0",
|
|
34
34
|
"@pnpm/error": "1100.0.0",
|
|
35
|
-
"@pnpm/
|
|
36
|
-
"@pnpm/
|
|
37
|
-
"@pnpm/
|
|
35
|
+
"@pnpm/fetching.types": "1100.0.1",
|
|
36
|
+
"@pnpm/core-loggers": "1100.1.0",
|
|
37
|
+
"@pnpm/types": "1101.1.0"
|
|
38
38
|
},
|
|
39
39
|
"peerDependencies": {
|
|
40
40
|
"@pnpm/logger": ">=1001.0.0 <1002.0.0"
|
|
@@ -42,7 +42,7 @@
|
|
|
42
42
|
"devDependencies": {
|
|
43
43
|
"@jest/globals": "30.3.0",
|
|
44
44
|
"https-proxy-server-express": "0.1.2",
|
|
45
|
-
"@pnpm/network.fetch": "1100.0.
|
|
45
|
+
"@pnpm/network.fetch": "1100.0.5",
|
|
46
46
|
"@pnpm/logger": "1100.0.0"
|
|
47
47
|
},
|
|
48
48
|
"engines": {
|