2
0
mirror of https://github.com/tenrok/axios.git synced 2026-06-08 17:22:34 +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:
Mathieu Bruyen
2014-09-18 09:07:08 +02:00
parent d8f687dc52
commit 095a204c5b
8 changed files with 124 additions and 9 deletions
+36
View File
@@ -45,6 +45,42 @@ describe('wrapper', function () {
}
});
it('should support binary data as array buffer', function () {
var input = new Int8Array(2);
input[0] = 1;
input[1] = 2;
axios({
method: 'post',
url: '/foo',
data: input.buffer
});
var request = jasmine.Ajax.requests.mostRecent();
var output = new Int8Array(request.params.buffer);
expect(output.length).toEqual(2);
expect(output[0]).toEqual(1);
expect(output[1]).toEqual(2);
});
it('should support binary data as array buffer view', function () {
var input = new Int8Array(2);
input[0] = 1;
input[1] = 2;
axios({
method: 'post',
url: '/foo',
data: input
});
var request = jasmine.Ajax.requests.mostRecent();
var output = new Int8Array(request.params.buffer);
expect(output.length).toEqual(2);
expect(output[0]).toEqual(1);
expect(output[1]).toEqual(2);
});
it('should remove content-type if data is empty', function () {
axios({
method: 'post',