From 69528093d940d3bc22373507dc929cdd6e7628df Mon Sep 17 00:00:00 2001 From: Jermolene Date: Wed, 5 Jul 2017 10:58:35 +0100 Subject: [PATCH] Update fetch commands to respect 302 redirects MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Astonishingly, node.js appears to require us to do this manually… --- core/modules/commands/fetch.js | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/core/modules/commands/fetch.js b/core/modules/commands/fetch.js index 1c28a0e99..8abd0b1bb 100644 --- a/core/modules/commands/fetch.js +++ b/core/modules/commands/fetch.js @@ -92,7 +92,10 @@ Command.prototype.fetchFiles = function(options) { return null; }; -Command.prototype.fetchFile = function(url,options,callback) { +Command.prototype.fetchFile = function(url,options,callback,redirectCount) { + if(redirectCount > 10) { + return callback("Error too many redirects retrieving " + url); + } var self = this, lib = url.substr(0,8) === "https://" ? require("https") : require("http"); lib.get(url).on("response",function(response) { @@ -109,7 +112,11 @@ Command.prototype.fetchFile = function(url,options,callback) { self.processBody(Buffer.concat(data),type,options,url); callback(null); } else { - callback("Error " + response.statusCode + " retrieving " + url) + if(response.statusCode === 302 || response.statusCode === 303 || response.statusCode === 307) { + return self.fetchFile(response.headers.location,options,callback,redirectCount + 1); + } else { + return callback("Error " + response.statusCode + " retrieving " + url) + } } }); response.on("error",function(e) {