Skip to content

Commit 81bff8e

Browse files
flentinihassy
authored andcommitted
fix(http): Emit "end" event even if the response is decompressed
1 parent 2dde495 commit 81bff8e

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

core/lib/engine_http.js

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -614,10 +614,12 @@ HttpEngine.prototype.step = function step(requestSpec, ee, opts) {
614614
};
615615

616616
HttpEngine.prototype._handleResponse = function(url, res, ee, context, maybeCallback, startedAt, callback) {
617-
res = decompressResponse(res);
617+
const decompressedRes = decompressResponse(res);
618618

619+
let code = decompressedRes.statusCode;
620+
const endedAt = process.hrtime(startedAt);
619621
if (!context._enableCookieJar) {
620-
const rawCookies = res.headers['set-cookie'];
622+
const rawCookies = decompressedRes.headers['set-cookie'];
621623
if (rawCookies) {
622624
context._enableCookieJar = true;
623625
rawCookies.forEach(function(cookieString) {
@@ -629,7 +631,7 @@ HttpEngine.prototype._handleResponse = function(url, res, ee, context, maybeCall
629631
ee.emit('response', res.timings.phases.firstByte * 1e6, res.statusCode, context._uid);
630632
let body = '';
631633
if (maybeCallback) {
632-
res.on('data', (d) => {
634+
decompressedRes.on('data', (d) => {
633635
body += d;
634636
});
635637
}

0 commit comments

Comments
 (0)