com.jimuwd.xian.registry-proxy 1.0.78 → 1.0.80
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 +11 -8
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -172,11 +172,7 @@ async function writeResponseToDownstreamClient(registryInfo, targetUrl, resToDow
|
|
|
172
172
|
// 准备通用头信息
|
|
173
173
|
const safeHeaders = { 'connection': connection, 'content-type': contentType, };
|
|
174
174
|
// 复制所有可能需要的头信息
|
|
175
|
-
const headersToCopy = [
|
|
176
|
-
// 'content-length', upstream response body is modified by proxy, the content-length is not valid anymore.
|
|
177
|
-
'content-encoding',
|
|
178
|
-
'transfer-encoding',
|
|
179
|
-
];
|
|
175
|
+
const headersToCopy = ['content-encoding', 'transfer-encoding',];
|
|
180
176
|
headersToCopy.forEach(header => {
|
|
181
177
|
const value = upstreamResponse.headers.get(header);
|
|
182
178
|
if (value)
|
|
@@ -199,8 +195,10 @@ async function writeResponseToDownstreamClient(registryInfo, targetUrl, resToDow
|
|
|
199
195
|
}
|
|
200
196
|
}
|
|
201
197
|
const bodyData = JSON.stringify(data);
|
|
202
|
-
|
|
203
|
-
|
|
198
|
+
if (!safeHeaders["transfer-encoding"]) {
|
|
199
|
+
// if transfer-encoding header is absent, then set the content-length header.
|
|
200
|
+
safeHeaders["content-length"] = bodyData.length;
|
|
201
|
+
}
|
|
204
202
|
resToDownstreamClient.writeHead(upstreamResponse.status, safeHeaders).end(bodyData);
|
|
205
203
|
}
|
|
206
204
|
else if (contentType.includes('application/octet-stream')) {
|
|
@@ -250,7 +248,12 @@ async function writeResponseToDownstreamClient(registryInfo, targetUrl, resToDow
|
|
|
250
248
|
}
|
|
251
249
|
else {
|
|
252
250
|
logger.warn(`Unsupported response content-type from upstream ${targetUrl}`);
|
|
253
|
-
|
|
251
|
+
const bodyData = await upstreamResponse.text();
|
|
252
|
+
if (!safeHeaders["transfer-encoding"]) {
|
|
253
|
+
// if transfer-encoding header is absent, then set the content-length header.
|
|
254
|
+
safeHeaders["content-length"] = bodyData.length;
|
|
255
|
+
}
|
|
256
|
+
resToDownstreamClient.writeHead(upstreamResponse.status, safeHeaders).end();
|
|
254
257
|
}
|
|
255
258
|
}
|
|
256
259
|
catch (err) {
|