feat: teach Downloader to respect redirects (#1741)

This patch adds support for redirects to downloader.

Fixes #1740
This commit is contained in:
刘祺 2018-01-09 10:10:13 +08:00 committed by Andrey Lushnikov
parent d7d9623740
commit 71089b0802

View File

@ -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;
}