mirror of
https://github.com/tenrok/axios.git
synced 2026-06-23 20:40:40 +03:00
committed by
Justin Beckwith
parent
d74238e151
commit
787c808c04
@@ -39,9 +39,9 @@ module.exports = function httpAdapter(config) {
|
|||||||
if (Buffer.isBuffer(data)) {
|
if (Buffer.isBuffer(data)) {
|
||||||
// Nothing to do...
|
// Nothing to do...
|
||||||
} else if (utils.isArrayBuffer(data)) {
|
} else if (utils.isArrayBuffer(data)) {
|
||||||
data = new Buffer(new Uint8Array(data));
|
data = Buffer.from(new Uint8Array(data));
|
||||||
} else if (utils.isString(data)) {
|
} else if (utils.isString(data)) {
|
||||||
data = new Buffer(data, 'utf-8');
|
data = Buffer.from(data, 'utf-8');
|
||||||
} else {
|
} else {
|
||||||
return reject(createError(
|
return reject(createError(
|
||||||
'Data after transformation must be a string, an ArrayBuffer, a Buffer, or a Stream',
|
'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
|
// Basic proxy authorization
|
||||||
if (proxy.auth) {
|
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;
|
options.headers['Proxy-Authorization'] = 'Basic ' + base64;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -181,7 +181,7 @@ module.exports = {
|
|||||||
var user = 'foo';
|
var user = 'foo';
|
||||||
var headers = { Authorization: 'Bearer 1234' };
|
var headers = { Authorization: 'Bearer 1234' };
|
||||||
axios.get('http://' + user + '@localhost:4444/', { headers: headers }).then(function (res) {
|
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.equal(res.data, 'Basic ' + base64);
|
||||||
test.done();
|
test.done();
|
||||||
});
|
});
|
||||||
@@ -195,7 +195,7 @@ module.exports = {
|
|||||||
var auth = { username: 'foo', password: 'bar' };
|
var auth = { username: 'foo', password: 'bar' };
|
||||||
var headers = { Authorization: 'Bearer 1234' };
|
var headers = { Authorization: 'Bearer 1234' };
|
||||||
axios.get('http://localhost:4444/', { auth: auth, headers: headers }).then(function (res) {
|
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.equal(res.data, 'Basic ' + base64);
|
||||||
test.done();
|
test.done();
|
||||||
});
|
});
|
||||||
@@ -288,7 +288,7 @@ module.exports = {
|
|||||||
},
|
},
|
||||||
|
|
||||||
testBuffer: function(test) {
|
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');
|
buf.fill('x');
|
||||||
server = http.createServer(function (req, res) {
|
server = http.createServer(function (req, res) {
|
||||||
test.equal(req.headers['content-length'], buf.length.toString());
|
test.equal(req.headers['content-length'], buf.length.toString());
|
||||||
@@ -437,7 +437,7 @@ module.exports = {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}).then(function(res) {
|
}).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.equal(res.data, 'Basic ' + base64, 'should authenticate to the proxy');
|
||||||
test.done();
|
test.done();
|
||||||
});
|
});
|
||||||
@@ -473,7 +473,7 @@ module.exports = {
|
|||||||
process.env.http_proxy = 'http://user:pass@localhost:4000/';
|
process.env.http_proxy = 'http://user:pass@localhost:4000/';
|
||||||
|
|
||||||
axios.get('http://localhost:4444/').then(function(res) {
|
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.equal(res.data, 'Basic ' + base64, 'should authenticate to the proxy set by process.env.http_proxy');
|
||||||
test.done();
|
test.done();
|
||||||
});
|
});
|
||||||
@@ -519,7 +519,7 @@ module.exports = {
|
|||||||
'Proxy-Authorization': 'Basic abc123'
|
'Proxy-Authorization': 'Basic abc123'
|
||||||
}
|
}
|
||||||
}).then(function(res) {
|
}).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.equal(res.data, 'Basic ' + base64, 'should authenticate to the proxy');
|
||||||
test.done();
|
test.done();
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user