diff --git a/lib/adapters/http.js b/lib/adapters/http.js index 0fe6a7d..8fc9e40 100755 --- a/lib/adapters/http.js +++ b/lib/adapters/http.js @@ -39,9 +39,9 @@ module.exports = function httpAdapter(config) { if (Buffer.isBuffer(data)) { // Nothing to do... } else if (utils.isArrayBuffer(data)) { - data = new Buffer(new Uint8Array(data)); + data = Buffer.from(new Uint8Array(data)); } else if (utils.isString(data)) { - data = new Buffer(data, 'utf-8'); + data = Buffer.from(data, 'utf-8'); } else { return reject(createError( 'Data after transformation must be a string, an ArrayBuffer, a Buffer, or a Stream', @@ -124,7 +124,7 @@ module.exports = function httpAdapter(config) { // Basic proxy authorization if (proxy.auth) { - var base64 = new Buffer(proxy.auth.username + ':' + proxy.auth.password, 'utf8').toString('base64'); + var base64 = Buffer.from(proxy.auth.username + ':' + proxy.auth.password, 'utf8').toString('base64'); options.headers['Proxy-Authorization'] = 'Basic ' + base64; } } diff --git a/test/unit/adapters/http.js b/test/unit/adapters/http.js index 48d8ac9..f88246c 100644 --- a/test/unit/adapters/http.js +++ b/test/unit/adapters/http.js @@ -181,7 +181,7 @@ module.exports = { var user = 'foo'; var headers = { Authorization: 'Bearer 1234' }; axios.get('http://' + user + '@localhost:4444/', { headers: headers }).then(function (res) { - var base64 = new Buffer(user + ':', 'utf8').toString('base64'); + var base64 = Buffer.from(user + ':', 'utf8').toString('base64'); test.equal(res.data, 'Basic ' + base64); test.done(); }); @@ -195,7 +195,7 @@ module.exports = { var auth = { username: 'foo', password: 'bar' }; var headers = { Authorization: 'Bearer 1234' }; axios.get('http://localhost:4444/', { auth: auth, headers: headers }).then(function (res) { - var base64 = new Buffer('foo:bar', 'utf8').toString('base64'); + var base64 = Buffer.from('foo:bar', 'utf8').toString('base64'); test.equal(res.data, 'Basic ' + base64); test.done(); }); @@ -288,7 +288,7 @@ module.exports = { }, testBuffer: function(test) { - var buf = new Buffer(1024); // Unsafe buffer < Buffer.poolSize (8192 bytes) + var buf = Buffer.from(1024); // Unsafe buffer < Buffer.poolSize (8192 bytes) buf.fill('x'); server = http.createServer(function (req, res) { test.equal(req.headers['content-length'], buf.length.toString()); @@ -437,7 +437,7 @@ module.exports = { } } }).then(function(res) { - var base64 = new Buffer('user:pass', 'utf8').toString('base64'); + var base64 = Buffer.from('user:pass', 'utf8').toString('base64'); test.equal(res.data, 'Basic ' + base64, 'should authenticate to the proxy'); test.done(); }); @@ -473,7 +473,7 @@ module.exports = { process.env.http_proxy = 'http://user:pass@localhost:4000/'; axios.get('http://localhost:4444/').then(function(res) { - var base64 = new Buffer('user:pass', 'utf8').toString('base64'); + var base64 = Buffer.from('user:pass', 'utf8').toString('base64'); test.equal(res.data, 'Basic ' + base64, 'should authenticate to the proxy set by process.env.http_proxy'); test.done(); }); @@ -519,7 +519,7 @@ module.exports = { 'Proxy-Authorization': 'Basic abc123' } }).then(function(res) { - var base64 = new Buffer('user:pass', 'utf8').toString('base64'); + var base64 = Buffer.from('user:pass', 'utf8').toString('base64'); test.equal(res.data, 'Basic ' + base64, 'should authenticate to the proxy'); test.done(); });