com.jimuwd.xian.registry-proxy 1.0.78 → 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 +9 -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
|
-
|
|
176
|
+
'content-length', // if you modify the body, you must reset the content-length.
|
|
177
177
|
'content-encoding',
|
|
178
178
|
'transfer-encoding',
|
|
179
179
|
];
|
|
@@ -199,8 +199,14 @@ async function writeResponseToDownstreamClient(registryInfo, targetUrl, resToDow
|
|
|
199
199
|
}
|
|
200
200
|
}
|
|
201
201
|
const bodyData = JSON.stringify(data);
|
|
202
|
-
|
|
203
|
-
|
|
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
|
+
}
|
|
204
210
|
resToDownstreamClient.writeHead(upstreamResponse.status, safeHeaders).end(bodyData);
|
|
205
211
|
}
|
|
206
212
|
else if (contentType.includes('application/octet-stream')) {
|