diff --git a/lib/needle.js b/lib/needle.js index 7a838062d..4bf08a7a7 100644 --- a/lib/needle.js +++ b/lib/needle.js @@ -549,8 +549,9 @@ Needle.prototype.send_request = function(count, method, uri, config, post_data, config.headers['host'] = null; // clear previous Host header to avoid conflicts. - debug('Redirecting to ' + url.resolve(uri, headers.location)); - return self.send_request(++count, method, url.resolve(uri, headers.location), config, post_data, out, callback); + let redirect_url = new url.URL(headers.location, uri); + debug('Redirecting to ' + redirect_url.toString()); + return self.send_request(++count, method, redirect_url.toString(), config, post_data, out, callback); } else if (config.follow_max > 0) { return done(new Error('Max redirects reached. Possible loop in: ' + headers.location)); }