Skip to content

Commit

Permalink
fix TypeError: binary is not a function (#243)
Browse files Browse the repository at this point in the history
  • Loading branch information
tommytroylin authored and floatdrop committed Nov 6, 2016
1 parent adfc6d1 commit c582d97
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,9 @@ function requestAsEventEmitter(opts) {
ee.emit('error', new got.MaxRedirectsError(statusCode, opts), null, res);
return;
}

redirectUrl = urlLib.resolve(urlLib.format(opts), Buffer.from(res.headers.location, 'binary').toString());
const isNode4 = process.version ? process.version.indexOf('v4.') === 0 : true;
const bufferString = isNode4 ? new Buffer(res.headers.location, 'binary').toString() : Buffer.from(res.headers.location, 'binary').toString();
redirectUrl = urlLib.resolve(urlLib.format(opts), bufferString);
const redirectOpts = Object.assign({}, opts, urlLib.parse(redirectUrl));

ee.emit('redirect', res, redirectOpts);
Expand Down

0 comments on commit c582d97

Please sign in to comment.