mirror of
https://github.com/tenrok/axios.git
synced 2026-06-14 18:42:33 +03:00
Allow ArrayBuffer and related views as data
In order to push binary data under the form of ArrayBuffer and its related views (Int8Array, ...) one needs not to stringify those. For the XHR adapter there is nothing to do as it natively supports ArrayBuffer in req.send(). Node's http adapter supports only string or Buffer thus a transformation to Buffer is required before setting content length header.
This commit is contained in:
@@ -4,6 +4,7 @@ var transformData = require('./../transformData');
|
||||
var utils = require('./../utils');
|
||||
var http = require('http');
|
||||
var url = require('url');
|
||||
var Buffer = require('buffer').Buffer;
|
||||
|
||||
module.exports = function httpAdapter(resolve, reject, config) {
|
||||
// Transform request data
|
||||
@@ -13,6 +14,10 @@ module.exports = function httpAdapter(resolve, reject, config) {
|
||||
config.transformRequest
|
||||
);
|
||||
|
||||
if (utils.isArrayBuffer(data)) {
|
||||
data = new Buffer(new Uint8Array(data));
|
||||
}
|
||||
|
||||
// Merge headers
|
||||
var headers = utils.merge(
|
||||
defaults.headers.common,
|
||||
|
||||
@@ -87,6 +87,10 @@ module.exports = function xhrAdapter(resolve, reject, config) {
|
||||
}
|
||||
}
|
||||
|
||||
if (utils.isArrayBuffer(data)) {
|
||||
data = new DataView(data);
|
||||
}
|
||||
|
||||
// Send the request
|
||||
request.send(data);
|
||||
};
|
||||
Reference in New Issue
Block a user