com.jimuwd.xian.registry-proxy 1.0.100 → 1.0.102
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 +13 -4
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -211,13 +211,22 @@ async function writeResponseToDownstreamClient(registryInfo, targetUrl, resToDow
|
|
|
211
211
|
// 必须使用 ServerResponse.setHeaders(safeHeaders)来覆盖现有headers而不是ServerResponse.writeHead(status,headers)来合并headers!
|
|
212
212
|
// 这个坑害我浪费很久事件来调试!
|
|
213
213
|
resToDownstreamClient.setHeaders(safeHeaders);
|
|
214
|
-
|
|
214
|
+
// 调试代码
|
|
215
|
+
resToDownstreamClient.removeHeader('Transfer-Encoding');
|
|
216
|
+
resToDownstreamClient.setHeader('Transfer-Encoding', 'chunked');
|
|
217
|
+
// 默认是 connection: keep-alive 和 keep-alive: timeout=5,这里直接给它咔嚓掉
|
|
218
|
+
resToDownstreamClient.removeHeader('Connection');
|
|
219
|
+
resToDownstreamClient.setHeader('Connection', 'close');
|
|
220
|
+
resToDownstreamClient.removeHeader('Keep-Alive');
|
|
221
|
+
resToDownstreamClient.removeHeader('content-type');
|
|
222
|
+
resToDownstreamClient.setHeader('content-type', contentType);
|
|
223
|
+
logger.info(`Response to downstream client headers`, JSON.stringify(resToDownstreamClient.getHeaders()), targetUrl);
|
|
215
224
|
resToDownstreamClient.writeHead(upstreamResponse.status);
|
|
216
225
|
// stop pipe when req from client is closed accidentally.
|
|
217
226
|
const cleanup = () => {
|
|
218
227
|
reqFromDownstreamClient.off('close', cleanup);
|
|
219
228
|
logger.info(`Req from downstream client is closed, stop pipe from upstream ${targetUrl} to downstream client.`);
|
|
220
|
-
upstreamResponse.body?.unpipe();
|
|
229
|
+
// upstreamResponse.body?.unpipe();
|
|
221
230
|
};
|
|
222
231
|
reqFromDownstreamClient.on('close', cleanup);
|
|
223
232
|
reqFromDownstreamClient.on('end', () => logger.info("Req from downstream client ends."));
|
|
@@ -225,7 +234,7 @@ async function writeResponseToDownstreamClient(registryInfo, targetUrl, resToDow
|
|
|
225
234
|
const cleanup0 = () => {
|
|
226
235
|
resToDownstreamClient.off('close', cleanup0);
|
|
227
236
|
logger.info(`Close connection to downstream client, upstream url is ${targetUrl}`);
|
|
228
|
-
upstreamResponse.body?.unpipe();
|
|
237
|
+
// upstreamResponse.body?.unpipe();
|
|
229
238
|
};
|
|
230
239
|
resToDownstreamClient.on('close', cleanup0);
|
|
231
240
|
// write back body data (chunked probably)
|
|
@@ -235,7 +244,7 @@ async function writeResponseToDownstreamClient(registryInfo, targetUrl, resToDow
|
|
|
235
244
|
.on('data', (chunk) => logger.info(`Chunk transferred from ${targetUrl} to downstream client size=${chunk.length}`))
|
|
236
245
|
.on('end', () => {
|
|
237
246
|
logger.info(`Upstream server ${targetUrl} response.body ended.`);
|
|
238
|
-
resToDownstreamClient.end();
|
|
247
|
+
// resToDownstreamClient.end();
|
|
239
248
|
})
|
|
240
249
|
// connection will be closed automatically when all chunk data is transferred (after stream ends).
|
|
241
250
|
.on('close', () => {
|