Skip to content

Commit

Permalink
feat: always follow redirects
Browse files Browse the repository at this point in the history
BREAKING CHANGE: the `followRedirects` option has been removed. Previous problems with non-GET redirects should be handled correctly now, the method is always forwarded as all redirects remain within the same host
  • Loading branch information
gr2m committed Nov 29, 2017
1 parent 0893c81 commit 61e7a81
Showing 1 changed file with 7 additions and 7 deletions.
14 changes: 7 additions & 7 deletions lib/index.js
Expand Up @@ -774,13 +774,7 @@ var Client = module.exports = function (config) {
}

function httpSendRequest () {
var reqModule
// Verbosity for WebPack compliance
if (self.config.followRedirects === false) {
reqModule = protocol === 'http' ? require('http') : require('https')
} else {
reqModule = protocol === 'http' ? require('follow-redirects/http') : require('follow-redirects/https')
}
var reqModule = protocol === 'http' ? require('http') : require('https')

var req = reqModule.request(options, function (res) {
if (self.debug) {
Expand All @@ -796,6 +790,12 @@ var Client = module.exports = function (config) {
callCallback(err)
})
res.on('end', function () {
if (res.statusCode >= 301 && res.statusCode <= 307) {
options.path = Url.parse(res.headers.location, true).path
httpSendRequest()
return
}

if (res.statusCode >= 400 || res.statusCode < 10) {
callCallback(new error.HttpError(data, res.statusCode, res.headers))
} else {
Expand Down

0 comments on commit 61e7a81

Please sign in to comment.