Skip to content

Commit

Permalink
fixed: URI malformed
Browse files Browse the repository at this point in the history
  • Loading branch information
Tjatse committed Aug 8, 2016
1 parent eda9e9b commit 63b9261
Showing 1 changed file with 9 additions and 5 deletions.
14 changes: 9 additions & 5 deletions lib/req_stream.js
Original file line number Diff line number Diff line change
Expand Up @@ -78,12 +78,16 @@ RequestStream.prototype.request = function () {
var status = res.statusCode;
if (!!~[301, 302, 303].indexOf(status)) {
if (!this.options.disableRedirect && this.redirects.length < this.options.maxRedirects) {
var nextTarget = URI(res.headers.location).absoluteTo(this.options.uri);
this.redirects.push(nextTarget.valueOf());

// reset client, host
this.client = myUtil.analyzeUri(nextTarget, this.options);
// handle `URI malformed` error.
try {
var nextTarget = URI(res.headers.location).absoluteTo(this.options.uri);
this.redirects.push(nextTarget.valueOf());

// reset client, host
this.client = myUtil.analyzeUri(nextTarget, this.options);
} catch (err) {
return this.emit('error', new Error('Failed to evaluate URI("'+ (res.headers.location || 'undefined') +'").absoluteTo("' + (this.options.uri || 'undefined') + '") due to ' + err.toString()));
}
if (this.options.trackCookie) {
var cookies = myUtil.cookieJar(res.headers['set-cookie']);
for (var k in cookies) {
Expand Down

0 comments on commit 63b9261

Please sign in to comment.