From 71089b08022d09c6a0fa20b5f0c770b5ef35ab07 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=88=98=E7=A5=BA?= Date: Tue, 9 Jan 2018 10:10:13 +0800 Subject: [PATCH] feat: teach Downloader to respect redirects (#1741) This patch adds support for redirects to downloader. Fixes #1740 --- lib/Downloader.js | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/lib/Downloader.js b/lib/Downloader.js index e782a328..c7d161a4 100644 --- a/lib/Downloader.js +++ b/lib/Downloader.js @@ -272,7 +272,12 @@ function httpRequest(url, method, response) { } const driver = options.protocol === 'https:' ? 'https' : 'http'; - const request = require(driver).request(options, response); + const request = require(driver).request(options, res => { + if (res.statusCode >= 300 && res.statusCode < 400 && res.headers.location) + httpRequest(res.headers.location, method, response); + else + response(res); + }); request.end(); return request; }