From 4a949f417845062dcd0416ba3644d6fb75de6d1e Mon Sep 17 00:00:00 2001 From: Tommy Troy Lin Date: Fri, 4 Nov 2016 14:02:21 +0800 Subject: [PATCH 1/3] Fix TypeError: binary is not a function --- index.js | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/index.js b/index.js index fe6b02f59..7b4f70817 100644 --- a/index.js +++ b/index.js @@ -40,8 +40,13 @@ 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); From db1ef7d8f62147e000079af065c47929a5d3957a Mon Sep 17 00:00:00 2001 From: Tommy Troy Lin Date: Fri, 4 Nov 2016 14:13:38 +0800 Subject: [PATCH 2/3] format code --- index.js | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/index.js b/index.js index 7b4f70817..a3969f1a2 100644 --- a/index.js +++ b/index.js @@ -40,12 +40,8 @@ function requestAsEventEmitter(opts) { ee.emit('error', new got.MaxRedirectsError(statusCode, opts), null, res); return; } - 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(); + 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)); From 10780c1c0c8d75607af0e7b8518ff8d069cafdb4 Mon Sep 17 00:00:00 2001 From: Tommy Troy Lin Date: Fri, 4 Nov 2016 14:17:35 +0800 Subject: [PATCH 3/3] format code --- index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/index.js b/index.js index a3969f1a2..6498236b7 100644 --- a/index.js +++ b/index.js @@ -40,7 +40,7 @@ function requestAsEventEmitter(opts) { ee.emit('error', new got.MaxRedirectsError(statusCode, opts), null, res); return; } - const isNode4 = process.version? process.version.indexOf('v4.') === 0 : true; + 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));