2
0
mirror of https://github.com/tenrok/axios.git synced 2026-06-08 17:22:34 +03:00

Fix: Removes usage of deprecated Buffer constructor. (#1555) (#1622)

This commit is contained in:
Mark van den Broek
2018-07-05 08:47:17 +02:00
committed by Justin Beckwith
parent d74238e151
commit 787c808c04
2 changed files with 9 additions and 9 deletions
+3 -3
View File
@@ -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;
}
}
+6 -6
View File
@@ -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();
});