com.jimuwd.xian.registry-proxy 1.0.43 → 1.0.45
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 +5 -4
- package/package.json +1 -1
- package/src/index.ts +6 -5
package/dist/index.js
CHANGED
|
@@ -142,9 +142,10 @@ async function fetchFromRegistry(registry, targetUrl, limiter) {
|
|
|
142
142
|
await limiter.acquire();
|
|
143
143
|
try {
|
|
144
144
|
console.log(`Fetching from: ${targetUrl}`);
|
|
145
|
-
const headers = registry.token ? { Authorization: `Bearer ${registry.token}` } :
|
|
145
|
+
const headers = registry.token ? { Authorization: `Bearer ${registry.token}` } : {};
|
|
146
|
+
headers.Collection = "keep-alive";
|
|
146
147
|
const response = await fetch(targetUrl, { headers });
|
|
147
|
-
console.log(`Response from ${targetUrl}: ${response.status} ${response.statusText} content-type=${response.headers.get("content-type")} content-length=${response.headers.get("content-length")}`);
|
|
148
|
+
console.log(`Response from upstream ${targetUrl}: ${response.status} ${response.statusText} content-type=${response.headers.get("content-type")} content-length=${response.headers.get("content-length")}`);
|
|
148
149
|
return response.ok ? response : null;
|
|
149
150
|
}
|
|
150
151
|
catch (e) {
|
|
@@ -165,7 +166,6 @@ async function writeSuccessfulResponse(registryInfo, targetUrl, res, response, r
|
|
|
165
166
|
throw new Error("Only 2xx response is supported");
|
|
166
167
|
try {
|
|
167
168
|
const upstreamContentType = response.headers.get('Content-Type');
|
|
168
|
-
console.log("Upstream Content-Type", upstreamContentType);
|
|
169
169
|
const contentType = upstreamContentType || 'application/octet-stream';
|
|
170
170
|
// 准备通用头信息
|
|
171
171
|
const safeHeaders = {
|
|
@@ -175,7 +175,8 @@ async function writeSuccessfulResponse(registryInfo, targetUrl, res, response, r
|
|
|
175
175
|
// 复制所有可能需要的头信息
|
|
176
176
|
const headersToCopy = [
|
|
177
177
|
'cache-control', 'etag', 'last-modified',
|
|
178
|
-
'content-encoding', 'content-length'
|
|
178
|
+
'content-encoding', 'content-length',
|
|
179
|
+
'transfer-encoding', "collection"
|
|
179
180
|
];
|
|
180
181
|
headersToCopy.forEach(header => {
|
|
181
182
|
const value = response.headers.get(header);
|
package/package.json
CHANGED
package/src/index.ts
CHANGED
|
@@ -194,9 +194,10 @@ async function fetchFromRegistry(
|
|
|
194
194
|
await limiter.acquire();
|
|
195
195
|
try {
|
|
196
196
|
console.log(`Fetching from: ${targetUrl}`);
|
|
197
|
-
const headers = registry.token ? {Authorization: `Bearer ${registry.token}`} :
|
|
197
|
+
const headers: {} = registry.token ? {Authorization: `Bearer ${registry.token}`} : {};
|
|
198
|
+
(headers as any).Collection = "keep-alive";
|
|
198
199
|
const response = await fetch(targetUrl, {headers});
|
|
199
|
-
console.log(`Response from ${targetUrl}: ${response.status} ${response.statusText} content-type=${response.headers.get("content-type")} content-length=${response.headers.get("content-length")}`);
|
|
200
|
+
console.log(`Response from upstream ${targetUrl}: ${response.status} ${response.statusText} content-type=${response.headers.get("content-type")} content-length=${response.headers.get("content-length")}`);
|
|
200
201
|
return response.ok ? response : null;
|
|
201
202
|
} catch (e) {
|
|
202
203
|
if (e instanceof Error) {
|
|
@@ -228,7 +229,6 @@ async function writeSuccessfulResponse(
|
|
|
228
229
|
|
|
229
230
|
try {
|
|
230
231
|
const upstreamContentType = response.headers.get('Content-Type');
|
|
231
|
-
console.log("Upstream Content-Type", upstreamContentType);
|
|
232
232
|
const contentType = upstreamContentType || 'application/octet-stream';
|
|
233
233
|
|
|
234
234
|
// 准备通用头信息
|
|
@@ -240,7 +240,8 @@ async function writeSuccessfulResponse(
|
|
|
240
240
|
// 复制所有可能需要的头信息
|
|
241
241
|
const headersToCopy = [
|
|
242
242
|
'cache-control', 'etag', 'last-modified',
|
|
243
|
-
'content-encoding', 'content-length'
|
|
243
|
+
'content-encoding', 'content-length',
|
|
244
|
+
'transfer-encoding', "collection"
|
|
244
245
|
];
|
|
245
246
|
|
|
246
247
|
headersToCopy.forEach(header => {
|
|
@@ -273,7 +274,7 @@ async function writeSuccessfulResponse(
|
|
|
273
274
|
if (!response.body) {
|
|
274
275
|
console.error(`Empty response body from ${targetUrl}`);
|
|
275
276
|
} else {
|
|
276
|
-
await pipeline(response.body, res).finally(()=>res.end());
|
|
277
|
+
await pipeline(response.body, res).finally(() => res.end());
|
|
277
278
|
}
|
|
278
279
|
}
|
|
279
280
|
} catch (err) {
|