com.jimuwd.xian.registry-proxy 1.0.77 → 1.0.79
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 +12 -3
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -173,7 +173,7 @@ async function writeResponseToDownstreamClient(registryInfo, targetUrl, resToDow
|
|
|
173
173
|
const safeHeaders = { 'connection': connection, 'content-type': contentType, };
|
|
174
174
|
// 复制所有可能需要的头信息
|
|
175
175
|
const headersToCopy = [
|
|
176
|
-
'content-length',
|
|
176
|
+
'content-length', // if you modify the body, you must reset the content-length.
|
|
177
177
|
'content-encoding',
|
|
178
178
|
'transfer-encoding',
|
|
179
179
|
];
|
|
@@ -198,7 +198,16 @@ async function writeResponseToDownstreamClient(registryInfo, targetUrl, resToDow
|
|
|
198
198
|
}
|
|
199
199
|
}
|
|
200
200
|
}
|
|
201
|
-
|
|
201
|
+
const bodyData = JSON.stringify(data);
|
|
202
|
+
if (!safeHeaders["transfer-encoding"]) {
|
|
203
|
+
// if transfer-encoding header is absent, then reset the content-length header.
|
|
204
|
+
// body is modified, reset the content-length
|
|
205
|
+
safeHeaders["content-length"] = bodyData.length;
|
|
206
|
+
}
|
|
207
|
+
else {
|
|
208
|
+
safeHeaders["content-length"] = undefined;
|
|
209
|
+
}
|
|
210
|
+
resToDownstreamClient.writeHead(upstreamResponse.status, safeHeaders).end(bodyData);
|
|
202
211
|
}
|
|
203
212
|
else if (contentType.includes('application/octet-stream')) {
|
|
204
213
|
// 二进制流处理
|
|
@@ -247,7 +256,7 @@ async function writeResponseToDownstreamClient(registryInfo, targetUrl, resToDow
|
|
|
247
256
|
}
|
|
248
257
|
else {
|
|
249
258
|
logger.warn(`Unsupported response content-type from upstream ${targetUrl}`);
|
|
250
|
-
resToDownstreamClient.writeHead(upstreamResponse.status,
|
|
259
|
+
resToDownstreamClient.writeHead(upstreamResponse.status, safeHeaders).end(upstreamResponse.text());
|
|
251
260
|
}
|
|
252
261
|
}
|
|
253
262
|
catch (err) {
|