mirror of
https://github.com/tenrok/axios.git
synced 2026-06-23 20:40:40 +03:00
@@ -52,15 +52,15 @@ module.exports = function httpAdapter(resolve, reject, config) {
|
|||||||
// Create the request
|
// Create the request
|
||||||
var transport = parsed.protocol === 'https:' ? https : http;
|
var transport = parsed.protocol === 'https:' ? https : http;
|
||||||
var req = transport.request(options, function (res) {
|
var req = transport.request(options, function (res) {
|
||||||
var responseText = '';
|
var responseBuffer = [];
|
||||||
res.on('data', function (chunk) {
|
res.on('data', function (chunk) {
|
||||||
responseText += chunk;
|
responseBuffer.push(chunk);
|
||||||
});
|
});
|
||||||
|
|
||||||
res.on('end', function () {
|
res.on('end', function () {
|
||||||
var response = {
|
var response = {
|
||||||
data: transformData(
|
data: transformData(
|
||||||
responseText,
|
Buffer.concat(responseBuffer).toString('utf8'),
|
||||||
res.headers,
|
res.headers,
|
||||||
config.transformResponse
|
config.transformResponse
|
||||||
),
|
),
|
||||||
|
|||||||
@@ -0,0 +1,44 @@
|
|||||||
|
var axios = require('../../../index');
|
||||||
|
var http = require('http');
|
||||||
|
var server;
|
||||||
|
|
||||||
|
module.exports = {
|
||||||
|
tearDown: function (callback) {
|
||||||
|
server.close();
|
||||||
|
server = null;
|
||||||
|
callback();
|
||||||
|
},
|
||||||
|
|
||||||
|
testJSON: function (test) {
|
||||||
|
console.log('testJSON');
|
||||||
|
var data = {
|
||||||
|
firstName: 'Fred',
|
||||||
|
lastName: 'Flintstone',
|
||||||
|
emailAddr: 'fred@example.com'
|
||||||
|
};
|
||||||
|
|
||||||
|
server = http.createServer(function (req, res) {
|
||||||
|
res.setHeader('Content-Type', 'application/json;charset=utf-8');
|
||||||
|
res.end(JSON.stringify(data));
|
||||||
|
}).listen(4444, function () {
|
||||||
|
axios.get('http://localhost:4444/').then(function (res) {
|
||||||
|
test.deepEqual(res.data, data);
|
||||||
|
test.done();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
},
|
||||||
|
|
||||||
|
testUTF8: function (test) {
|
||||||
|
var str = Array(100000).join('ж');
|
||||||
|
|
||||||
|
server = http.createServer(function (req, res) {
|
||||||
|
res.setHeader('Content-Type', 'text/html; charset=UTF-8');
|
||||||
|
res.end(str);
|
||||||
|
}).listen(4444, function () {
|
||||||
|
axios.get('http://localhost:4444/').then(function (res) {
|
||||||
|
test.equal(res.data, str);
|
||||||
|
test.done();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
|
};
|
||||||
Reference in New Issue
Block a user