From 159c3994a88324705c8b048ed68f156268400690 Mon Sep 17 00:00:00 2001 From: Luke Childs Date: Tue, 16 May 2017 19:05:57 +0700 Subject: [PATCH] Use pipe instead of manually piping inside data --- index.js | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/index.js b/index.js index ef78ed8..a5a5e1b 100644 --- a/index.js +++ b/index.js @@ -212,21 +212,19 @@ function asStream(opts) { if (opts.cache && policy.storable()) { const bodyChunks = []; res.on('data', chunk => { - output.push(chunk); bodyChunks.push(chunk); }); res.on('end', () => { - output.push(null); res.body = Buffer.concat(bodyChunks); if (opts.encoding !== null) { res.body = res.body.toString(opts.encoding); } cacheResponse(res, policy, opts); }); - } else { - res.pipe(output); } + res.pipe(output); + if (statusCode !== 304 && (statusCode < 200 || statusCode > 299)) { proxy.emit('error', new got.HTTPError(statusCode, opts), null, res); return;