Skip to content
This repository was archived by the owner on Mar 11, 2025. It is now read-only.

Commit 7fb93ec

Browse files
committed
feat: when get a chunked res, flush (by: yohox)
1 parent 7ac4bb5 commit 7fb93ec

2 files changed

Lines changed: 34 additions & 0 deletions

File tree

lib/http-proxy/passes/web-outgoing.js

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,4 +141,20 @@ module.exports = {
141141
res.statusMessage = proxyRes.statusMessage;
142142
}
143143
},
144+
145+
/**
146+
* If is a chunked response, flush headers.
147+
*
148+
* @param {ClientRequest} Req Request object
149+
* @param {IncomingMessage} Res Response object
150+
* @param {proxyResponse} Res Response object from the proxy request
151+
*
152+
* @api private
153+
*/
154+
chunkedResponse: function chunkedResponse(req, res, proxyRes) {
155+
const te = proxyRes.headers["transfer-encoding"];
156+
if (te && te.toLowerCase() === "chunked") {
157+
res.flushHeaders();
158+
}
159+
},
144160
};

test/lib-http-proxy-passes-web-outgoing-test.js

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -444,4 +444,22 @@ describe("lib/http-proxy/passes/web-outgoing.js", function () {
444444

445445
expect(proxyRes.headers["transfer-encoding"]).to.eql(undefined);
446446
});
447+
448+
describe("#chunkedHeader", function () {
449+
const proxyRes = {
450+
headers: {
451+
"transfer-encoding": "chunked",
452+
},
453+
};
454+
let b = false;
455+
const res = {
456+
flushHeaders: () => {
457+
b = true;
458+
},
459+
};
460+
461+
httpProxy.chunkedResponse({}, res, proxyRes);
462+
463+
expect(b).to.eql(true);
464+
});
447465
});

0 commit comments

Comments
 (0)