com.jimuwd.xian.registry-proxy 1.0.103 → 1.0.105
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 +10 -5
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -202,7 +202,7 @@ async function writeResponseToDownstreamClient(registryInfo, targetUrl, resToDow
|
|
|
202
202
|
safeHeaders.set("Content-Type", contentType);
|
|
203
203
|
// 复制所有可能需要的头信息(不包含安全相关的敏感头信息,如access-control-allow-origin、set-cookie、server、strict-transport-security等,这意味着代理服务器向下游客户端屏蔽了这些认证等安全数据)
|
|
204
204
|
// 也不能包含cf-cache-status、cf-ray(Cloudflare 特有字段)可能干扰客户端解析。
|
|
205
|
-
const headersToCopy = ['cache-control', 'connection', 'content-encoding', 'content-length', 'date'
|
|
205
|
+
const headersToCopy = ['cache-control', 'connection', 'content-encoding', 'content-length', /*'date',*/ 'etag', 'last-modified', 'transfer-encoding', 'vary',];
|
|
206
206
|
headersToCopy.forEach(header => {
|
|
207
207
|
const value = upstreamResponse.headers.get(header);
|
|
208
208
|
if (value)
|
|
@@ -212,16 +212,21 @@ async function writeResponseToDownstreamClient(registryInfo, targetUrl, resToDow
|
|
|
212
212
|
// 这个坑害我浪费很久事件来调试!
|
|
213
213
|
resToDownstreamClient.setHeaders(safeHeaders);
|
|
214
214
|
// 调试代码
|
|
215
|
+
resToDownstreamClient.removeHeader('content-encoding');
|
|
215
216
|
resToDownstreamClient.removeHeader('Transfer-Encoding');
|
|
216
|
-
resToDownstreamClient.
|
|
217
|
+
resToDownstreamClient.removeHeader('content-length');
|
|
218
|
+
resToDownstreamClient.setHeader('transfer-encoding', 'chunked');
|
|
217
219
|
// 默认是 connection: keep-alive 和 keep-alive: timeout=5,这里直接给它咔嚓掉
|
|
218
|
-
resToDownstreamClient.removeHeader('
|
|
219
|
-
resToDownstreamClient.setHeader('
|
|
220
|
+
resToDownstreamClient.removeHeader('connection');
|
|
221
|
+
resToDownstreamClient.setHeader('connection', 'close');
|
|
220
222
|
resToDownstreamClient.removeHeader('Keep-Alive');
|
|
221
223
|
resToDownstreamClient.removeHeader('content-type');
|
|
222
224
|
resToDownstreamClient.setHeader('content-type', contentType);
|
|
223
225
|
logger.info(`Response to downstream client headers`, JSON.stringify(resToDownstreamClient.getHeaders()), targetUrl);
|
|
224
|
-
|
|
226
|
+
// 不再writeHead()而是设置状态码,然后执行pipe操作
|
|
227
|
+
resToDownstreamClient.statusCode = upstreamResponse.status;
|
|
228
|
+
resToDownstreamClient.statusMessage = upstreamResponse.statusText;
|
|
229
|
+
// resToDownstreamClient.writeHead(upstreamResponse.status);
|
|
225
230
|
// stop pipe when req from client is closed accidentally.
|
|
226
231
|
const cleanup = () => {
|
|
227
232
|
reqFromDownstreamClient.off('close', cleanup);
|