2
0
mirror of https://github.com/tenrok/axios.git synced 2026-06-17 19:21:29 +03:00

Axios ES2017 (#4787)

* Added AxiosHeaders class;

* Fixed README.md href;

* Fixed a potential bug with headers normalization;

* Fixed a potential bug with headers normalization;
Refactored accessor building routine;
Refactored default transforms;
Removed `normalizeHeaderName` helper;

* Added `Content-Length` accessor;
Added missed `has` accessor to TS types;

* Added `AxiosTransformStream` class;
Added progress capturing ability for node.js environment;
Added `maxRate` option to limit the data rate in node.js environment;
Refactored event handled by `onUploadProgress` && `onDownloadProgress` listeners in browser environment;
Added progress & data rate tests for the http adapter;
Added response stream aborting test;
Added a manual progress capture test for the browser;
Updated TS types;
Added TS tests;
Refactored request abort logic for the http adapter;
Added ability to abort the response stream;

* Remove `stream/promises` & `timers/promises` modules usage in tests;

* Use `abortcontroller-polyfill`;

* Fixed AxiosTransformStream dead-lock in legacy node versions;
Fixed CancelError emitting in streams;

* Reworked AxiosTransformStream internal logic to optimize memory consumption;
Added throwing an error if the request stream was silently destroying (without error) Refers to #3966;

* Treat the destruction of the request stream as a cancellation of the request;
Fixed tests;

* Emit `progress` event in the next tick;

* Initial refactoring;

* Refactored Mocha tests to use ESM;

* Refactored Karma tests to use rollup preprocessor & ESM;
Replaced grunt with gulp;
Improved dev scripts;
Added Babel for rollup build;

* Added default commonjs package export for Node build;
Added automatic contributors list generator for package.json;

Co-authored-by: Jay <jasonsaayman@gmail.com>
This commit is contained in:
Dmitriy Mozgovoy
2022-06-18 12:19:27 +03:00
committed by GitHub
parent 1db715dd3b
commit bdf493cf8b
125 changed files with 10462 additions and 7291 deletions
+37 -37
View File
@@ -112,13 +112,13 @@ describe('requests', function () {
// disable jasmine.Ajax since we're hitting a non-existent server anyway
jasmine.Ajax.uninstall();
var resolveSpy = jasmine.createSpy('resolve');
var rejectSpy = jasmine.createSpy('reject');
const resolveSpy = jasmine.createSpy('resolve');
const rejectSpy = jasmine.createSpy('reject');
var finish = function () {
const finish = function () {
expect(resolveSpy).not.toHaveBeenCalled();
expect(rejectSpy).toHaveBeenCalled();
var reason = rejectSpy.calls.first().args[0];
const reason = rejectSpy.calls.first().args[0];
expect(reason instanceof Error).toBe(true);
expect(reason.config.method).toBe('get');
expect(reason.config.url).toBe('http://thisisnotaserver/foo');
@@ -136,13 +136,13 @@ describe('requests', function () {
});
it('should reject on abort', function (done) {
var resolveSpy = jasmine.createSpy('resolve');
var rejectSpy = jasmine.createSpy('reject');
const resolveSpy = jasmine.createSpy('resolve');
const rejectSpy = jasmine.createSpy('reject');
var finish = function () {
const finish = function () {
expect(resolveSpy).not.toHaveBeenCalled();
expect(rejectSpy).toHaveBeenCalled();
var reason = rejectSpy.calls.first().args[0];
const reason = rejectSpy.calls.first().args[0];
expect(reason instanceof Error).toBe(true);
expect(reason.config.method).toBe('get');
expect(reason.config.url).toBe('/foo');
@@ -161,8 +161,8 @@ describe('requests', function () {
});
it('should reject when validateStatus returns false', function (done) {
var resolveSpy = jasmine.createSpy('resolve');
var rejectSpy = jasmine.createSpy('reject');
const resolveSpy = jasmine.createSpy('resolve');
const rejectSpy = jasmine.createSpy('reject');
axios('/foo', {
validateStatus: function (status) {
@@ -173,7 +173,7 @@ describe('requests', function () {
.then(function () {
expect(resolveSpy).not.toHaveBeenCalled();
expect(rejectSpy).toHaveBeenCalled();
var reason = rejectSpy.calls.first().args[0];
const reason = rejectSpy.calls.first().args[0];
expect(reason instanceof Error).toBe(true);
expect(reason.message).toBe('Request failed with status code 500');
expect(reason.config.method).toBe('get');
@@ -191,8 +191,8 @@ describe('requests', function () {
});
it('should resolve when validateStatus returns true', function (done) {
var resolveSpy = jasmine.createSpy('resolve');
var rejectSpy = jasmine.createSpy('reject');
const resolveSpy = jasmine.createSpy('resolve');
const rejectSpy = jasmine.createSpy('reject');
axios('/foo', {
validateStatus: function (status) {
@@ -214,8 +214,8 @@ describe('requests', function () {
});
it('should resolve when the response status is 0 (i.e. requesting with file protocol)', function (done) {
var resolveSpy = jasmine.createSpy('resolve');
var rejectSpy = jasmine.createSpy('reject');
const resolveSpy = jasmine.createSpy('resolve');
const rejectSpy = jasmine.createSpy('reject');
axios('file:///xxx').then(resolveSpy)
.catch(rejectSpy)
@@ -234,8 +234,8 @@ describe('requests', function () {
});
it('should resolve when validateStatus is null', function (done) {
var resolveSpy = jasmine.createSpy('resolve');
var rejectSpy = jasmine.createSpy('reject');
const resolveSpy = jasmine.createSpy('resolve');
const rejectSpy = jasmine.createSpy('reject');
axios('/foo', {
validateStatus: null
@@ -255,8 +255,8 @@ describe('requests', function () {
});
it('should resolve when validateStatus is undefined', function (done) {
var resolveSpy = jasmine.createSpy('resolve');
var rejectSpy = jasmine.createSpy('reject');
const resolveSpy = jasmine.createSpy('resolve');
const rejectSpy = jasmine.createSpy('reject');
axios('/foo', {
validateStatus: undefined
@@ -277,7 +277,7 @@ describe('requests', function () {
// https://github.com/axios/axios/issues/378
it('should return JSON when rejecting', function (done) {
var response;
let response;
axios('/api/account/signup', {
username: null,
@@ -309,7 +309,7 @@ describe('requests', function () {
});
it('should make cross domain http request', function (done) {
var response;
let response;
axios.post('www.someurl.com/foo').then(function(res){
response = res;
@@ -337,7 +337,7 @@ describe('requests', function () {
it('should supply correct response', function (done) {
var response;
let response;
axios.post('/foo').then(function (res) {
response = res;
@@ -364,7 +364,7 @@ describe('requests', function () {
});
it('should not modify the config url with relative baseURL', function (done) {
var config;
let config;
axios.get('/foo', {
baseURL: '/api'
@@ -388,12 +388,12 @@ describe('requests', function () {
});
it('should allow overriding Content-Type header case-insensitive', function (done) {
var response;
var contentType = 'application/vnd.myapp.type+json';
let response;
const contentType = 'application/vnd.myapp.type+json';
axios.post('/foo', { prop: 'value' }, {
headers: {
'content-type': contentType
'Content-Type': contentType
}
}).then(function (res) {
response = res;
@@ -406,14 +406,14 @@ describe('requests', function () {
});
it('should support binary data as array buffer', function (done) {
var input = new Int8Array(2);
const input = new Int8Array(2);
input[0] = 1;
input[1] = 2;
axios.post('/foo', input.buffer);
getAjaxRequest().then(function (request) {
var output = new Int8Array(request.params);
const output = new Int8Array(request.params);
expect(output.length).toEqual(2);
expect(output[0]).toEqual(1);
expect(output[1]).toEqual(2);
@@ -422,14 +422,14 @@ describe('requests', function () {
});
it('should support binary data as array buffer view', function (done) {
var input = new Int8Array(2);
const input = new Int8Array(2);
input[0] = 1;
input[1] = 2;
axios.post('/foo', input);
getAjaxRequest().then(function (request) {
var output = new Int8Array(request.params);
const output = new Int8Array(request.params);
expect(output.length).toEqual(2);
expect(output[0]).toEqual(1);
expect(output[1]).toEqual(2);
@@ -438,12 +438,12 @@ describe('requests', function () {
});
it('should support array buffer response', function (done) {
var response;
let response;
function str2ab(str) {
var buff = new ArrayBuffer(str.length * 2);
var view = new Uint16Array(buff);
for ( var i=0, l=str.length; i<l; i++) {
const buff = new ArrayBuffer(str.length * 2);
const view = new Uint16Array(buff);
for ( let i=0, l=str.length; i<l; i++) {
view[i] = str.charCodeAt(i);
}
return buff;
@@ -469,7 +469,7 @@ describe('requests', function () {
});
it('should support URLSearchParams', function (done) {
var params = new URLSearchParams();
const params = new URLSearchParams();
params.append('param1', 'value1');
params.append('param2', 'value2');
@@ -483,7 +483,7 @@ describe('requests', function () {
});
it('should support HTTP protocol', function (done) {
var response;
let response;
axios.get('/foo')
.then(function (res) {
@@ -500,7 +500,7 @@ describe('requests', function () {
});
it('should support HTTPS protocol', function (done) {
var response;
let response;
axios.get('https://www.google.com')
.then(function (res) {
response = res