com.jimuwd.xian.registry-proxy 1.0.49 → 1.0.51
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/dist/index.js +8 -11
- package/package.json +1 -1
- package/src/index.ts +8 -11
package/dist/index.js
CHANGED
|
@@ -33,7 +33,7 @@ class ConcurrencyLimiter {
|
|
|
33
33
|
}
|
|
34
34
|
}
|
|
35
35
|
}
|
|
36
|
-
const limiter = new ConcurrencyLimiter(
|
|
36
|
+
const limiter = new ConcurrencyLimiter(10);
|
|
37
37
|
function removeEndingSlashAndForceStartingSlash(str) {
|
|
38
38
|
if (!str)
|
|
39
39
|
return '/';
|
|
@@ -144,7 +144,7 @@ async function fetchFromRegistry(registry, targetUrl, limiter) {
|
|
|
144
144
|
const headers = registry.token ? { Authorization: `Bearer ${registry.token}` } : {};
|
|
145
145
|
headers.Collection = "keep-alive";
|
|
146
146
|
const response = await fetch(targetUrl, { headers });
|
|
147
|
-
console.log(`Response from upstream ${targetUrl}: ${response.status} ${response.statusText}
|
|
147
|
+
console.log(`Response from upstream ${targetUrl}: ${response.status} ${response.statusText} headers=${response.headers}`);
|
|
148
148
|
return response.ok ? response : null;
|
|
149
149
|
}
|
|
150
150
|
catch (e) {
|
|
@@ -164,16 +164,13 @@ async function writeSuccessfulResponse(registryInfo, targetUrl, res, upstreamRes
|
|
|
164
164
|
if (!upstreamResponse.ok)
|
|
165
165
|
throw new Error("Only 2xx upstream response is supported");
|
|
166
166
|
try {
|
|
167
|
-
const
|
|
168
|
-
const
|
|
169
|
-
const contentType = upstreamContentType || 'application/octet-stream';
|
|
170
|
-
const connection = upstreamConnection || 'keep-alive';
|
|
167
|
+
const contentType = upstreamResponse.headers.get('content-type') || 'application/octet-stream';
|
|
168
|
+
const connection = upstreamResponse.headers.get("connection") || 'keep-alive';
|
|
171
169
|
// 准备通用头信息
|
|
172
170
|
const safeHeaders = { 'connection': connection, 'content-type': contentType, };
|
|
173
171
|
// 复制所有可能需要的头信息
|
|
174
172
|
const headersToCopy = [
|
|
175
|
-
'etag', 'last-modified',
|
|
176
|
-
'cache-control',
|
|
173
|
+
// 'etag', 'last-modified', 'cache-control',
|
|
177
174
|
'content-length',
|
|
178
175
|
'content-encoding',
|
|
179
176
|
'transfer-encoding',
|
|
@@ -251,9 +248,9 @@ export async function startProxyServer(proxyConfigPath, localYarnConfigPath, glo
|
|
|
251
248
|
targetRegistry = registry;
|
|
252
249
|
const search = fullUrl.search || '';
|
|
253
250
|
targetUrl = `${registry.normalizedRegistryUrl}${path}${search}`;
|
|
254
|
-
const
|
|
255
|
-
if (
|
|
256
|
-
successfulResponse =
|
|
251
|
+
const okResponseOrNull = await fetchFromRegistry(registry, targetUrl, limiter);
|
|
252
|
+
if (okResponseOrNull) {
|
|
253
|
+
successfulResponse = okResponseOrNull;
|
|
257
254
|
break;
|
|
258
255
|
}
|
|
259
256
|
}
|
package/package.json
CHANGED
package/src/index.ts
CHANGED
|
@@ -78,7 +78,7 @@ class ConcurrencyLimiter {
|
|
|
78
78
|
}
|
|
79
79
|
}
|
|
80
80
|
|
|
81
|
-
const limiter = new ConcurrencyLimiter(
|
|
81
|
+
const limiter = new ConcurrencyLimiter(10);
|
|
82
82
|
|
|
83
83
|
function removeEndingSlashAndForceStartingSlash(str: string | undefined | null): string {
|
|
84
84
|
if (!str) return '/';
|
|
@@ -196,7 +196,7 @@ async function fetchFromRegistry(
|
|
|
196
196
|
const headers: {} = registry.token ? {Authorization: `Bearer ${registry.token}`} : {};
|
|
197
197
|
(headers as any).Collection = "keep-alive";
|
|
198
198
|
const response = await fetch(targetUrl, {headers});
|
|
199
|
-
console.log(`Response from upstream ${targetUrl}: ${response.status} ${response.statusText}
|
|
199
|
+
console.log(`Response from upstream ${targetUrl}: ${response.status} ${response.statusText} headers=${response.headers}`);
|
|
200
200
|
return response.ok ? response : null;
|
|
201
201
|
} catch (e) {
|
|
202
202
|
if (e instanceof Error) {
|
|
@@ -227,18 +227,15 @@ async function writeSuccessfulResponse(
|
|
|
227
227
|
if (!upstreamResponse.ok) throw new Error("Only 2xx upstream response is supported");
|
|
228
228
|
|
|
229
229
|
try {
|
|
230
|
-
const
|
|
231
|
-
const
|
|
232
|
-
const contentType = upstreamContentType || 'application/octet-stream';
|
|
233
|
-
const connection = upstreamConnection || 'keep-alive';
|
|
230
|
+
const contentType = upstreamResponse.headers.get('content-type') || 'application/octet-stream';
|
|
231
|
+
const connection = upstreamResponse.headers.get("connection") || 'keep-alive';
|
|
234
232
|
|
|
235
233
|
// 准备通用头信息
|
|
236
234
|
const safeHeaders: OutgoingHttpHeaders = {'connection': connection, 'content-type': contentType,};
|
|
237
235
|
|
|
238
236
|
// 复制所有可能需要的头信息
|
|
239
237
|
const headersToCopy = [
|
|
240
|
-
'etag', 'last-modified',
|
|
241
|
-
'cache-control',
|
|
238
|
+
// 'etag', 'last-modified', 'cache-control',
|
|
242
239
|
'content-length',
|
|
243
240
|
'content-encoding',
|
|
244
241
|
'transfer-encoding',
|
|
@@ -326,9 +323,9 @@ export async function startProxyServer(
|
|
|
326
323
|
targetRegistry = registry;
|
|
327
324
|
const search = fullUrl.search || '';
|
|
328
325
|
targetUrl = `${registry.normalizedRegistryUrl}${path}${search}`;
|
|
329
|
-
const
|
|
330
|
-
if (
|
|
331
|
-
successfulResponse =
|
|
326
|
+
const okResponseOrNull = await fetchFromRegistry(registry, targetUrl, limiter);
|
|
327
|
+
if (okResponseOrNull) {
|
|
328
|
+
successfulResponse = okResponseOrNull;
|
|
332
329
|
break;
|
|
333
330
|
}
|
|
334
331
|
}
|