From 8fcc40edf27b0e8db9bd2585b00b50779c1b66a1 Mon Sep 17 00:00:00 2001 From: Rafael Oleza Date: Mon, 16 Apr 2018 04:17:51 -0700 Subject: [PATCH] Clean not found/error requests from nodejs HTTP agent Differential Revision: D7635421 fbshipit-source-id: 2a825a99ce57857354f17496239a9537bf068bc2 --- packages/metro-cache/src/stores/HttpStore.js | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/packages/metro-cache/src/stores/HttpStore.js b/packages/metro-cache/src/stores/HttpStore.js index 13636845..ea616958 100644 --- a/packages/metro-cache/src/stores/HttpStore.js +++ b/packages/metro-cache/src/stores/HttpStore.js @@ -77,11 +77,16 @@ class HttpStore { const req = this._module.request(options, res => { let data = ''; - if (res.statusCode === 404) { - resolve(null); - return; - } else if (res.statusCode !== 200) { - reject(new Error('HTTP error: ' + res.statusCode)); + if (res.statusCode !== 200) { + // Consume all the data from the response without processing it. + res.resume(); + + if (res.statusCode === 404) { + resolve(null); + } else { + reject(new Error('HTTP error: ' + res.statusCode)); + } + return; } @@ -135,6 +140,9 @@ class HttpStore { res.on('end', () => { resolve(); }); + + // Consume all the data from the response without processing it. + res.resume(); }); gzip.pipe(req);