2
0
mirror of https://github.com/tenrok/axios.git synced 2026-06-20 20:00:40 +03:00

Release/v0.22.0 (#4107)

* fix/Avoid package.json import; (#4041)

* Added auto-generated config module `env/data.js` for importing package environment vars without importing the whole `package.json`;
Refactored `http.js` to use `env/data.js` instead of package.json;

* Added `env/data.js`;
Added `env/README.md`;

* Feat/export package version constant (#4065)

* Added auto-generated config module `env/data.js` for importing package environment vars without importing the whole `package.json`;
Refactored `http.js` to use `env/data.js` instead of package.json;

* Added `env/data.js`;
Added `env/README.md`;

* Export package version constant;

* Fixed cancelToken leakage; Added AbortController support; (#3305)

* Fixed cancelToken leakage;
Added AbortController support;

* Fixed typings;

* Documented `signal` option;

* Added processing of early cancellation using AbortController without sending a request;

Co-authored-by: Jay <jasonsaayman@gmail.com>

* Updating CI to run on release branches

* Fixed default transitional config for custom Axios instance; (#4052)

Refactored `/core/mergeConfig`;

Co-authored-by: Jay <jasonsaayman@gmail.com>

* Prepping v0.22.0 for release

* Updated date

Co-authored-by: Dmitriy Mozgovoy <robotshara@gmail.com>
This commit is contained in:
Jay
2021-10-01 08:02:13 +02:00
committed by GitHub
parent 7d6bddba2d
commit 76f09afc03
27 changed files with 623 additions and 365 deletions
+124 -121
View File
@@ -1,148 +1,151 @@
// eslint-disable-next-line strict
module.exports = { module.exports = {
"globals": { 'globals': {
"console": true, 'console': true,
"module": true, 'module': true,
"require": true 'require': true
}, },
"env": { 'env': {
"browser": true, 'browser': true,
"node": true 'node': true
}, },
"rules": { 'rules': {
/** /**
* Strict mode * Strict mode
*/ */
"strict": [2, "global"], // http://eslint.org/docs/rules/strict 'strict': [2, 'global'], // http://eslint.org/docs/rules/strict
/** /**
* Variables * Variables
*/ */
"no-shadow": 2, // http://eslint.org/docs/rules/no-shadow 'no-shadow': 2, // http://eslint.org/docs/rules/no-shadow
"no-shadow-restricted-names": 2, // http://eslint.org/docs/rules/no-shadow-restricted-names 'no-shadow-restricted-names': 2, // http://eslint.org/docs/rules/no-shadow-restricted-names
"no-unused-vars": [2, { // http://eslint.org/docs/rules/no-unused-vars 'no-unused-vars': [2, { // http://eslint.org/docs/rules/no-unused-vars
"vars": "local", 'vars': 'local',
"args": "after-used" 'args': 'after-used'
}], }],
"no-use-before-define": 2, // http://eslint.org/docs/rules/no-use-before-define 'no-use-before-define': 2, // http://eslint.org/docs/rules/no-use-before-define
/** /**
* Possible errors * Possible errors
*/ */
"comma-dangle": [2, "never"], // http://eslint.org/docs/rules/comma-dangle 'comma-dangle': [2, 'never'], // http://eslint.org/docs/rules/comma-dangle
"no-cond-assign": [2, "except-parens"], // http://eslint.org/docs/rules/no-cond-assign 'no-cond-assign': [2, 'except-parens'], // http://eslint.org/docs/rules/no-cond-assign
"no-console": 1, // http://eslint.org/docs/rules/no-console 'no-console': 1, // http://eslint.org/docs/rules/no-console
"no-debugger": 1, // http://eslint.org/docs/rules/no-debugger 'no-debugger': 1, // http://eslint.org/docs/rules/no-debugger
"no-alert": 1, // http://eslint.org/docs/rules/no-alert 'no-alert': 1, // http://eslint.org/docs/rules/no-alert
"no-constant-condition": 1, // http://eslint.org/docs/rules/no-constant-condition 'no-constant-condition': 1, // http://eslint.org/docs/rules/no-constant-condition
"no-dupe-keys": 2, // http://eslint.org/docs/rules/no-dupe-keys 'no-dupe-keys': 2, // http://eslint.org/docs/rules/no-dupe-keys
"no-duplicate-case": 2, // http://eslint.org/docs/rules/no-duplicate-case 'no-duplicate-case': 2, // http://eslint.org/docs/rules/no-duplicate-case
"no-empty": 2, // http://eslint.org/docs/rules/no-empty 'no-empty': 2, // http://eslint.org/docs/rules/no-empty
"no-ex-assign": 2, // http://eslint.org/docs/rules/no-ex-assign 'no-ex-assign': 2, // http://eslint.org/docs/rules/no-ex-assign
"no-extra-boolean-cast": 0, // http://eslint.org/docs/rules/no-extra-boolean-cast 'no-extra-boolean-cast': 0, // http://eslint.org/docs/rules/no-extra-boolean-cast
"no-extra-semi": 2, // http://eslint.org/docs/rules/no-extra-semi 'no-extra-semi': 2, // http://eslint.org/docs/rules/no-extra-semi
"no-func-assign": 2, // http://eslint.org/docs/rules/no-func-assign 'no-func-assign': 2, // http://eslint.org/docs/rules/no-func-assign
"no-inner-declarations": 2, // http://eslint.org/docs/rules/no-inner-declarations 'no-inner-declarations': 2, // http://eslint.org/docs/rules/no-inner-declarations
"no-invalid-regexp": 2, // http://eslint.org/docs/rules/no-invalid-regexp 'no-invalid-regexp': 2, // http://eslint.org/docs/rules/no-invalid-regexp
"no-irregular-whitespace": 2, // http://eslint.org/docs/rules/no-irregular-whitespace 'no-irregular-whitespace': 2, // http://eslint.org/docs/rules/no-irregular-whitespace
"no-obj-calls": 2, // http://eslint.org/docs/rules/no-obj-calls 'no-obj-calls': 2, // http://eslint.org/docs/rules/no-obj-calls
"no-sparse-arrays": 2, // http://eslint.org/docs/rules/no-sparse-arrays 'no-sparse-arrays': 2, // http://eslint.org/docs/rules/no-sparse-arrays
"no-unreachable": 2, // http://eslint.org/docs/rules/no-unreachable 'no-unreachable': 2, // http://eslint.org/docs/rules/no-unreachable
"use-isnan": 2, // http://eslint.org/docs/rules/use-isnan 'use-isnan': 2, // http://eslint.org/docs/rules/use-isnan
"block-scoped-var": 2, // http://eslint.org/docs/rules/block-scoped-var 'block-scoped-var': 2, // http://eslint.org/docs/rules/block-scoped-var
/** /**
* Best practices * Best practices
*/ */
"consistent-return": 2, // http://eslint.org/docs/rules/consistent-return 'consistent-return': 2, // http://eslint.org/docs/rules/consistent-return
"curly": [2, "multi-line"], // http://eslint.org/docs/rules/curly 'curly': [2, 'multi-line'], // http://eslint.org/docs/rules/curly
"default-case": 2, // http://eslint.org/docs/rules/default-case 'default-case': 2, // http://eslint.org/docs/rules/default-case
"dot-notation": [2, { // http://eslint.org/docs/rules/dot-notation 'dot-notation': [2, { // http://eslint.org/docs/rules/dot-notation
"allowKeywords": true 'allowKeywords': true
}], }],
"eqeqeq": 2, // http://eslint.org/docs/rules/eqeqeq 'eqeqeq': 2, // http://eslint.org/docs/rules/eqeqeq
"guard-for-in": 2, // http://eslint.org/docs/rules/guard-for-in 'guard-for-in': 2, // http://eslint.org/docs/rules/guard-for-in
"no-caller": 2, // http://eslint.org/docs/rules/no-caller 'no-caller': 2, // http://eslint.org/docs/rules/no-caller
"no-else-return": 2, // http://eslint.org/docs/rules/no-else-return 'no-else-return': 2, // http://eslint.org/docs/rules/no-else-return
"no-eq-null": 2, // http://eslint.org/docs/rules/no-eq-null 'no-eq-null': 2, // http://eslint.org/docs/rules/no-eq-null
"no-eval": 2, // http://eslint.org/docs/rules/no-eval 'no-eval': 2, // http://eslint.org/docs/rules/no-eval
"no-extend-native": 2, // http://eslint.org/docs/rules/no-extend-native 'no-extend-native': 2, // http://eslint.org/docs/rules/no-extend-native
"no-extra-bind": 2, // http://eslint.org/docs/rules/no-extra-bind 'no-extra-bind': 2, // http://eslint.org/docs/rules/no-extra-bind
"no-fallthrough": 2, // http://eslint.org/docs/rules/no-fallthrough 'no-fallthrough': 2, // http://eslint.org/docs/rules/no-fallthrough
"no-floating-decimal": 2, // http://eslint.org/docs/rules/no-floating-decimal 'no-floating-decimal': 2, // http://eslint.org/docs/rules/no-floating-decimal
"no-implied-eval": 2, // http://eslint.org/docs/rules/no-implied-eval 'no-implied-eval': 2, // http://eslint.org/docs/rules/no-implied-eval
"no-lone-blocks": 2, // http://eslint.org/docs/rules/no-lone-blocks 'no-lone-blocks': 2, // http://eslint.org/docs/rules/no-lone-blocks
"no-loop-func": 2, // http://eslint.org/docs/rules/no-loop-func 'no-loop-func': 2, // http://eslint.org/docs/rules/no-loop-func
"no-multi-str": 2, // http://eslint.org/docs/rules/no-multi-str 'no-multi-str': 2, // http://eslint.org/docs/rules/no-multi-str
"no-native-reassign": 2, // http://eslint.org/docs/rules/no-native-reassign 'no-native-reassign': 2, // http://eslint.org/docs/rules/no-native-reassign
"no-new": 2, // http://eslint.org/docs/rules/no-new 'no-new': 2, // http://eslint.org/docs/rules/no-new
"no-new-func": 2, // http://eslint.org/docs/rules/no-new-func 'no-new-func': 2, // http://eslint.org/docs/rules/no-new-func
"no-new-wrappers": 2, // http://eslint.org/docs/rules/no-new-wrappers 'no-new-wrappers': 2, // http://eslint.org/docs/rules/no-new-wrappers
"no-octal": 2, // http://eslint.org/docs/rules/no-octal 'no-octal': 2, // http://eslint.org/docs/rules/no-octal
"no-octal-escape": 2, // http://eslint.org/docs/rules/no-octal-escape 'no-octal-escape': 2, // http://eslint.org/docs/rules/no-octal-escape
"no-param-reassign": 2, // http://eslint.org/docs/rules/no-param-reassign 'no-param-reassign': 2, // http://eslint.org/docs/rules/no-param-reassign
"no-proto": 2, // http://eslint.org/docs/rules/no-proto 'no-proto': 2, // http://eslint.org/docs/rules/no-proto
"no-redeclare": 2, // http://eslint.org/docs/rules/no-redeclare 'no-redeclare': 2, // http://eslint.org/docs/rules/no-redeclare
"no-return-assign": 2, // http://eslint.org/docs/rules/no-return-assign 'no-return-assign': 2, // http://eslint.org/docs/rules/no-return-assign
"no-script-url": 2, // http://eslint.org/docs/rules/no-script-url 'no-script-url': 2, // http://eslint.org/docs/rules/no-script-url
"no-self-compare": 2, // http://eslint.org/docs/rules/no-self-compare 'no-self-compare': 2, // http://eslint.org/docs/rules/no-self-compare
"no-sequences": 2, // http://eslint.org/docs/rules/no-sequences 'no-sequences': 2, // http://eslint.org/docs/rules/no-sequences
"no-throw-literal": 2, // http://eslint.org/docs/rules/no-throw-literal 'no-throw-literal': 2, // http://eslint.org/docs/rules/no-throw-literal
"no-with": 2, // http://eslint.org/docs/rules/no-with 'no-with': 2, // http://eslint.org/docs/rules/no-with
"radix": 2, // http://eslint.org/docs/rules/radix 'radix': 2, // http://eslint.org/docs/rules/radix
"vars-on-top": 0, // http://eslint.org/docs/rules/vars-on-top 'vars-on-top': 0, // http://eslint.org/docs/rules/vars-on-top
"wrap-iife": [2, "any"], // http://eslint.org/docs/rules/wrap-iife 'wrap-iife': [2, 'any'], // http://eslint.org/docs/rules/wrap-iife
"yoda": 2, // http://eslint.org/docs/rules/yoda 'yoda': 2, // http://eslint.org/docs/rules/yoda
/** /**
* Style * Style
*/ */
"indent": [2, 2], // http://eslint.org/docs/rules/indent 'indent': [2, 2], // http://eslint.org/docs/rules/indent
"brace-style": [2, // http://eslint.org/docs/rules/brace-style 'brace-style': [2, // http://eslint.org/docs/rules/brace-style
"1tbs", { '1tbs', {
"allowSingleLine": true 'allowSingleLine': true
}], }],
"quotes": [ 'quotes': [
2, "single", "avoid-escape" // http://eslint.org/docs/rules/quotes 2, 'single', 'avoid-escape' // http://eslint.org/docs/rules/quotes
], ],
"camelcase": [2, { // http://eslint.org/docs/rules/camelcase 'camelcase': [2, { // http://eslint.org/docs/rules/camelcase
"properties": "never" 'properties': 'never'
}], }],
"comma-spacing": [2, { // http://eslint.org/docs/rules/comma-spacing 'comma-spacing': [2, { // http://eslint.org/docs/rules/comma-spacing
"before": false, 'before': false,
"after": true 'after': true
}], }],
"comma-style": [2, "last"], // http://eslint.org/docs/rules/comma-style 'comma-style': [2, 'last'], // http://eslint.org/docs/rules/comma-style
"eol-last": 2, // http://eslint.org/docs/rules/eol-last 'eol-last': 2, // http://eslint.org/docs/rules/eol-last
"func-names": 1, // http://eslint.org/docs/rules/func-names 'func-names': 1, // http://eslint.org/docs/rules/func-names
"key-spacing": [2, { // http://eslint.org/docs/rules/key-spacing 'key-spacing': [2, { // http://eslint.org/docs/rules/key-spacing
"beforeColon": false, 'beforeColon': false,
"afterColon": true 'afterColon': true
}], }],
"new-cap": [2, { // http://eslint.org/docs/rules/new-cap 'new-cap': [2, { // http://eslint.org/docs/rules/new-cap
"newIsCap": true 'newIsCap': true
}], }],
"no-multiple-empty-lines": [2, { // http://eslint.org/docs/rules/no-multiple-empty-lines 'no-multiple-empty-lines': [2, { // http://eslint.org/docs/rules/no-multiple-empty-lines
"max": 2 'max': 2
}], }],
"no-nested-ternary": 2, // http://eslint.org/docs/rules/no-nested-ternary 'no-nested-ternary': 2, // http://eslint.org/docs/rules/no-nested-ternary
"no-new-object": 2, // http://eslint.org/docs/rules/no-new-object 'no-new-object': 2, // http://eslint.org/docs/rules/no-new-object
"no-spaced-func": 2, // http://eslint.org/docs/rules/no-spaced-func 'no-spaced-func': 2, // http://eslint.org/docs/rules/no-spaced-func
"no-trailing-spaces": 2, // http://eslint.org/docs/rules/no-trailing-spaces 'no-trailing-spaces': 2, // http://eslint.org/docs/rules/no-trailing-spaces
"no-extra-parens": [2, "functions"], // http://eslint.org/docs/rules/no-extra-parens 'no-extra-parens': [2, 'functions'], // http://eslint.org/docs/rules/no-extra-parens
"no-underscore-dangle": 0, // http://eslint.org/docs/rules/no-underscore-dangle 'no-underscore-dangle': 0, // http://eslint.org/docs/rules/no-underscore-dangle
"one-var": [2, "never"], // http://eslint.org/docs/rules/one-var 'one-var': [2, 'never'], // http://eslint.org/docs/rules/one-var
"padded-blocks": [2, "never"], // http://eslint.org/docs/rules/padded-blocks 'padded-blocks': [2, 'never'], // http://eslint.org/docs/rules/padded-blocks
"semi": [2, "always"], // http://eslint.org/docs/rules/semi 'semi': [2, 'always'], // http://eslint.org/docs/rules/semi
"semi-spacing": [2, { // http://eslint.org/docs/rules/semi-spacing 'semi-spacing': [2, { // http://eslint.org/docs/rules/semi-spacing
"before": false, 'before': false,
"after": true 'after': true
}], }],
"keyword-spacing": 2, // http://eslint.org/docs/rules/keyword-spacing 'keyword-spacing': 2, // http://eslint.org/docs/rules/keyword-spacing
"space-before-blocks": 2, // http://eslint.org/docs/rules/space-before-blocks 'space-before-blocks': 2, // http://eslint.org/docs/rules/space-before-blocks
"space-before-function-paren": [2, "never"], // http://eslint.org/docs/rules/space-before-function-paren 'space-before-function-paren': [2, 'never'], // http://eslint.org/docs/rules/space-before-function-paren
"space-infix-ops": 2, // http://eslint.org/docs/rules/space-infix-ops 'space-infix-ops': 2, // http://eslint.org/docs/rules/space-infix-ops
"spaced-comment": [2, "always", {// http://eslint.org/docs/rules/spaced-comment 'spaced-comment': [2, 'always', {// http://eslint.org/docs/rules/spaced-comment
"markers": ["global", "eslint"] 'markers': ['global', 'eslint']
}] }]
} },
}
'ignorePatterns': ['**/env/data.js']
};
+2 -2
View File
@@ -2,9 +2,9 @@ name: ci
on: on:
push: push:
branches: [master] branches: [master, 'release/*']
pull_request: pull_request:
branches: [master] branches: [master, 'release/*']
jobs: jobs:
build: build:
+17
View File
@@ -1,5 +1,22 @@
# Changelog # Changelog
### 0.22.0 (October 01, 2021)
Fixes and Functionality:
- Caseless header comparing in HTTP adapter ([#2880](https://github.com/axios/axios/pull/2880))
- Avoid package.json import fixing issues and warnings related to this ([#4041](https://github.com/axios/axios/pull/4041)), ([#4065](https://github.com/axios/axios/pull/4065))
- Fixed cancelToken leakage and added AbortController support ([#3305](https://github.com/axios/axios/pull/3305))
- Updating CI to run on release branches
- Bump follow redirects version
- Fixed default transitional config for custom Axios instance; ([#4052](https://github.com/axios/axios/pull/4052))
Huge thanks to everyone who contributed to this release via code (authors listed below) or via reviews and triaging on GitHub:
- [Jay](mailto:jasonsaayman@gmail.com)
- [Matt R. Wilson](https://github.com/mastermatt)
- [Xianming Zhong](https://github.com/chinesedfan)
- [Dmitriy Mozgovoy](https://github.com/DigitalBrainJS)
### 0.21.4 (September 6, 2021) ### 0.21.4 (September 6, 2021)
Fixes and Functionality: Fixes and Functionality:
+20 -5
View File
@@ -1,3 +1,4 @@
// eslint-disable-next-line strict
module.exports = function(grunt) { module.exports = function(grunt) {
require('load-grunt-tasks')(grunt); require('load-grunt-tasks')(grunt);
@@ -37,6 +38,10 @@ module.exports = function(grunt) {
} }
}, },
package2env: {
all: {}
},
usebanner: { usebanner: {
all: { all: {
options: { options: {
@@ -70,8 +75,8 @@ module.exports = function(grunt) {
src: ['test/unit/**/*.js'] src: ['test/unit/**/*.js']
}, },
options: { options: {
timeout: 30000, timeout: 30000
}, }
}, },
watch: { watch: {
@@ -88,12 +93,12 @@ module.exports = function(grunt) {
webpack: require('./webpack.config.js') webpack: require('./webpack.config.js')
}); });
grunt.registerMultiTask('package2bower', 'Sync package.json to bower.json', function () { grunt.registerMultiTask('package2bower', 'Sync package.json to bower.json', function() {
var npm = grunt.file.readJSON('package.json'); var npm = grunt.file.readJSON('package.json');
var bower = grunt.file.readJSON('bower.json'); var bower = grunt.file.readJSON('bower.json');
var fields = this.data.fields || []; var fields = this.data.fields || [];
for (var i=0, l=fields.length; i<l; i++) { for (var i = 0, l = fields.length; i < l; i++) {
var field = fields[i]; var field = fields[i];
bower[field] = npm[field]; bower[field] = npm[field];
} }
@@ -101,7 +106,17 @@ module.exports = function(grunt) {
grunt.file.write('bower.json', JSON.stringify(bower, null, 2)); grunt.file.write('bower.json', JSON.stringify(bower, null, 2));
}); });
grunt.registerMultiTask('package2env', 'Sync package.json to env.json', function() {
var npm = grunt.file.readJSON('package.json');
grunt.file.write('./lib/env/data.js', [
'module.exports = ',
JSON.stringify({
version: npm.version
}, null, 2),
';'].join(''));
});
grunt.registerTask('test', 'Run the jasmine and mocha tests', ['eslint', 'mochaTest', 'karma:single', 'ts']); grunt.registerTask('test', 'Run the jasmine and mocha tests', ['eslint', 'mochaTest', 'karma:single', 'ts']);
grunt.registerTask('build', 'Run webpack and bundle the source', ['clean', 'webpack']); grunt.registerTask('build', 'Run webpack and bundle the source', ['clean', 'webpack']);
grunt.registerTask('version', 'Sync version info for a release', ['usebanner', 'package2bower']); grunt.registerTask('version', 'Sync version info for a release', ['usebanner', 'package2bower', 'package2env']);
}; };
+17 -1
View File
@@ -452,6 +452,9 @@ These are the available config options for making requests. Only the `url` is re
cancelToken: new CancelToken(function (cancel) { cancelToken: new CancelToken(function (cancel) {
}), }),
// an alternative way to cancel Axios requests using AbortController
signal: new AbortController().signal,
// `decompress` indicates whether or not the response body should be decompressed // `decompress` indicates whether or not the response body should be decompressed
// automatically. If set to `true` will also remove the 'content-encoding' header // automatically. If set to `true` will also remove the 'content-encoding' header
// from the responses objects of all decompressed responses // from the responses objects of all decompressed responses
@@ -734,7 +737,20 @@ axios.get('/user/12345', {
cancel(); cancel();
``` ```
> Note: you can cancel several requests with the same cancel token. Axios supports AbortController to abort requests in [`fetch API`](https://developer.mozilla.org/en-US/docs/Web/API/Fetch_API#aborting_a_fetch) way:
```js
const controller = new AbortController();
axios.get('/foo/bar', {
signal: controller.signal
}).then(function(response) {
//...
});
// cancel the request
controller.abort()
```
> Note: you can cancel several requests with the same cancel token/abort controller.
> If a cancellation token is already cancelled at the moment of starting an Axios request, then the request is cancelled immediately, without any attempts to make real request. > If a cancellation token is already cancelled at the moment of starting an Axios request, then the request is cancelled immediately, without any attempts to make real request.
## Using application/x-www-form-urlencoded format ## Using application/x-www-form-urlencoded format
+1 -1
View File
@@ -1,7 +1,7 @@
{ {
"name": "axios", "name": "axios",
"main": "./dist/axios.js", "main": "./dist/axios.js",
"version": "0.21.4", "version": "0.22.0",
"homepage": "https://axios-http.com", "homepage": "https://axios-http.com",
"authors": [ "authors": [
"Matt Zabriskie" "Matt Zabriskie"
+186 -104
View File
@@ -1,4 +1,3 @@
/* axios v0.21.4 | (c) 2021 by Matt Zabriskie */
(function webpackUniversalModuleDefinition(root, factory) { (function webpackUniversalModuleDefinition(root, factory) {
if(typeof exports === 'object' && typeof module === 'object') if(typeof exports === 'object' && typeof module === 'object')
module.exports = factory(); module.exports = factory();
@@ -126,12 +125,24 @@ var buildFullPath = __webpack_require__(/*! ../core/buildFullPath */ "./lib/core
var parseHeaders = __webpack_require__(/*! ./../helpers/parseHeaders */ "./lib/helpers/parseHeaders.js"); var parseHeaders = __webpack_require__(/*! ./../helpers/parseHeaders */ "./lib/helpers/parseHeaders.js");
var isURLSameOrigin = __webpack_require__(/*! ./../helpers/isURLSameOrigin */ "./lib/helpers/isURLSameOrigin.js"); var isURLSameOrigin = __webpack_require__(/*! ./../helpers/isURLSameOrigin */ "./lib/helpers/isURLSameOrigin.js");
var createError = __webpack_require__(/*! ../core/createError */ "./lib/core/createError.js"); var createError = __webpack_require__(/*! ../core/createError */ "./lib/core/createError.js");
var defaults = __webpack_require__(/*! ../defaults */ "./lib/defaults.js");
var Cancel = __webpack_require__(/*! ../cancel/Cancel */ "./lib/cancel/Cancel.js");
module.exports = function xhrAdapter(config) { module.exports = function xhrAdapter(config) {
return new Promise(function dispatchXhrRequest(resolve, reject) { return new Promise(function dispatchXhrRequest(resolve, reject) {
var requestData = config.data; var requestData = config.data;
var requestHeaders = config.headers; var requestHeaders = config.headers;
var responseType = config.responseType; var responseType = config.responseType;
var onCanceled;
function done() {
if (config.cancelToken) {
config.cancelToken.unsubscribe(onCanceled);
}
if (config.signal) {
config.signal.removeEventListener('abort', onCanceled);
}
}
if (utils.isFormData(requestData)) { if (utils.isFormData(requestData)) {
delete requestHeaders['Content-Type']; // Let the browser set it delete requestHeaders['Content-Type']; // Let the browser set it
@@ -169,7 +180,13 @@ module.exports = function xhrAdapter(config) {
request: request request: request
}; };
settle(resolve, reject, response); settle(function _resolve(value) {
resolve(value);
done();
}, function _reject(err) {
reject(err);
done();
}, response);
// Clean up request // Clean up request
request = null; request = null;
@@ -223,13 +240,14 @@ module.exports = function xhrAdapter(config) {
// Handle timeout // Handle timeout
request.ontimeout = function handleTimeout() { request.ontimeout = function handleTimeout() {
var timeoutErrorMessage = 'timeout of ' + config.timeout + 'ms exceeded'; var timeoutErrorMessage = 'timeout of ' + config.timeout + 'ms exceeded';
var transitional = config.transitional || defaults.transitional;
if (config.timeoutErrorMessage) { if (config.timeoutErrorMessage) {
timeoutErrorMessage = config.timeoutErrorMessage; timeoutErrorMessage = config.timeoutErrorMessage;
} }
reject(createError( reject(createError(
timeoutErrorMessage, timeoutErrorMessage,
config, config,
config.transitional && config.transitional.clarifyTimeoutError ? 'ETIMEDOUT' : 'ECONNABORTED', transitional.clarifyTimeoutError ? 'ETIMEDOUT' : 'ECONNABORTED',
request)); request));
// Clean up request // Clean up request
@@ -283,18 +301,22 @@ module.exports = function xhrAdapter(config) {
request.upload.addEventListener('progress', config.onUploadProgress); request.upload.addEventListener('progress', config.onUploadProgress);
} }
if (config.cancelToken) { if (config.cancelToken || config.signal) {
// Handle cancellation // Handle cancellation
config.cancelToken.promise.then(function onCanceled(cancel) { // eslint-disable-next-line func-names
onCanceled = function(cancel) {
if (!request) { if (!request) {
return; return;
} }
reject(!cancel || (cancel && cancel.type) ? new Cancel('canceled') : cancel);
request.abort(); request.abort();
reject(cancel);
// Clean up request
request = null; request = null;
}); };
config.cancelToken && config.cancelToken.subscribe(onCanceled);
if (config.signal) {
config.signal.aborted ? onCanceled() : config.signal.addEventListener('abort', onCanceled);
}
} }
if (!requestData) { if (!requestData) {
@@ -341,6 +363,11 @@ function createInstance(defaultConfig) {
// Copy context to instance // Copy context to instance
utils.extend(instance, context); utils.extend(instance, context);
// Factory for creating new instances
instance.create = function create(instanceConfig) {
return createInstance(mergeConfig(defaultConfig, instanceConfig));
};
return instance; return instance;
} }
@@ -350,15 +377,11 @@ var axios = createInstance(defaults);
// Expose Axios class to allow class inheritance // Expose Axios class to allow class inheritance
axios.Axios = Axios; axios.Axios = Axios;
// Factory for creating new instances
axios.create = function create(instanceConfig) {
return createInstance(mergeConfig(axios.defaults, instanceConfig));
};
// Expose Cancel & CancelToken // Expose Cancel & CancelToken
axios.Cancel = __webpack_require__(/*! ./cancel/Cancel */ "./lib/cancel/Cancel.js"); axios.Cancel = __webpack_require__(/*! ./cancel/Cancel */ "./lib/cancel/Cancel.js");
axios.CancelToken = __webpack_require__(/*! ./cancel/CancelToken */ "./lib/cancel/CancelToken.js"); axios.CancelToken = __webpack_require__(/*! ./cancel/CancelToken */ "./lib/cancel/CancelToken.js");
axios.isCancel = __webpack_require__(/*! ./cancel/isCancel */ "./lib/cancel/isCancel.js"); axios.isCancel = __webpack_require__(/*! ./cancel/isCancel */ "./lib/cancel/isCancel.js");
axios.VERSION = __webpack_require__(/*! ./env/data */ "./lib/env/data.js").version;
// Expose all/spread // Expose all/spread
axios.all = function all(promises) { axios.all = function all(promises) {
@@ -432,11 +455,42 @@ function CancelToken(executor) {
} }
var resolvePromise; var resolvePromise;
this.promise = new Promise(function promiseExecutor(resolve) { this.promise = new Promise(function promiseExecutor(resolve) {
resolvePromise = resolve; resolvePromise = resolve;
}); });
var token = this; var token = this;
// eslint-disable-next-line func-names
this.promise.then(function(cancel) {
if (!token._listeners) return;
var i;
var l = token._listeners.length;
for (i = 0; i < l; i++) {
token._listeners[i](cancel);
}
token._listeners = null;
});
// eslint-disable-next-line func-names
this.promise.then = function(onfulfilled) {
var _resolve;
// eslint-disable-next-line func-names
var promise = new Promise(function(resolve) {
token.subscribe(resolve);
_resolve = resolve;
}).then(onfulfilled);
promise.cancel = function reject() {
token.unsubscribe(_resolve);
};
return promise;
};
executor(function cancel(message) { executor(function cancel(message) {
if (token.reason) { if (token.reason) {
// Cancellation has already been requested // Cancellation has already been requested
@@ -457,6 +511,37 @@ CancelToken.prototype.throwIfRequested = function throwIfRequested() {
} }
}; };
/**
* Subscribe to the cancel signal
*/
CancelToken.prototype.subscribe = function subscribe(listener) {
if (this.reason) {
listener(this.reason);
return;
}
if (this._listeners) {
this._listeners.push(listener);
} else {
this._listeners = [listener];
}
};
/**
* Unsubscribe from the cancel signal
*/
CancelToken.prototype.unsubscribe = function unsubscribe(listener) {
if (!this._listeners) {
return;
}
var index = this._listeners.indexOf(listener);
if (index !== -1) {
this._listeners.splice(index, 1);
}
};
/** /**
* Returns an object that contains a new `CancelToken` and a function that, when called, * Returns an object that contains a new `CancelToken` and a function that, when called,
* cancels the `CancelToken`. * cancels the `CancelToken`.
@@ -555,9 +640,9 @@ Axios.prototype.request = function request(config) {
if (transitional !== undefined) { if (transitional !== undefined) {
validator.assertOptions(transitional, { validator.assertOptions(transitional, {
silentJSONParsing: validators.transitional(validators.boolean, '1.0.0'), silentJSONParsing: validators.transitional(validators.boolean),
forcedJSONParsing: validators.transitional(validators.boolean, '1.0.0'), forcedJSONParsing: validators.transitional(validators.boolean),
clarifyTimeoutError: validators.transitional(validators.boolean, '1.0.0') clarifyTimeoutError: validators.transitional(validators.boolean)
}, false); }, false);
} }
@@ -796,6 +881,7 @@ var utils = __webpack_require__(/*! ./../utils */ "./lib/utils.js");
var transformData = __webpack_require__(/*! ./transformData */ "./lib/core/transformData.js"); var transformData = __webpack_require__(/*! ./transformData */ "./lib/core/transformData.js");
var isCancel = __webpack_require__(/*! ../cancel/isCancel */ "./lib/cancel/isCancel.js"); var isCancel = __webpack_require__(/*! ../cancel/isCancel */ "./lib/cancel/isCancel.js");
var defaults = __webpack_require__(/*! ../defaults */ "./lib/defaults.js"); var defaults = __webpack_require__(/*! ../defaults */ "./lib/defaults.js");
var Cancel = __webpack_require__(/*! ../cancel/Cancel */ "./lib/cancel/Cancel.js");
/** /**
* Throws a `Cancel` if cancellation has been requested. * Throws a `Cancel` if cancellation has been requested.
@@ -804,6 +890,10 @@ function throwIfCancellationRequested(config) {
if (config.cancelToken) { if (config.cancelToken) {
config.cancelToken.throwIfRequested(); config.cancelToken.throwIfRequested();
} }
if (config.signal && config.signal.aborted) {
throw new Cancel('canceled');
}
} }
/** /**
@@ -921,7 +1011,8 @@ module.exports = function enhanceError(error, config, code, request, response) {
stack: this.stack, stack: this.stack,
// Axios // Axios
config: this.config, config: this.config,
code: this.code code: this.code,
status: this.response && this.response.status ? this.response.status : null
}; };
}; };
return error; return error;
@@ -955,17 +1046,6 @@ module.exports = function mergeConfig(config1, config2) {
config2 = config2 || {}; config2 = config2 || {};
var config = {}; var config = {};
var valueFromConfig2Keys = ['url', 'method', 'data'];
var mergeDeepPropertiesKeys = ['headers', 'auth', 'proxy', 'params'];
var defaultToConfig2Keys = [
'baseURL', 'transformRequest', 'transformResponse', 'paramsSerializer',
'timeout', 'timeoutMessage', 'withCredentials', 'adapter', 'responseType', 'xsrfCookieName',
'xsrfHeaderName', 'onUploadProgress', 'onDownloadProgress', 'decompress',
'maxContentLength', 'maxBodyLength', 'maxRedirects', 'transport', 'httpAgent',
'httpsAgent', 'cancelToken', 'socketPath', 'responseEncoding'
];
var directMergeKeys = ['validateStatus'];
function getMergedValue(target, source) { function getMergedValue(target, source) {
if (utils.isPlainObject(target) && utils.isPlainObject(source)) { if (utils.isPlainObject(target) && utils.isPlainObject(source)) {
return utils.merge(target, source); return utils.merge(target, source);
@@ -977,52 +1057,75 @@ module.exports = function mergeConfig(config1, config2) {
return source; return source;
} }
// eslint-disable-next-line consistent-return
function mergeDeepProperties(prop) { function mergeDeepProperties(prop) {
if (!utils.isUndefined(config2[prop])) { if (!utils.isUndefined(config2[prop])) {
config[prop] = getMergedValue(config1[prop], config2[prop]); return getMergedValue(config1[prop], config2[prop]);
} else if (!utils.isUndefined(config1[prop])) { } else if (!utils.isUndefined(config1[prop])) {
config[prop] = getMergedValue(undefined, config1[prop]); return getMergedValue(undefined, config1[prop]);
} }
} }
utils.forEach(valueFromConfig2Keys, function valueFromConfig2(prop) { // eslint-disable-next-line consistent-return
function valueFromConfig2(prop) {
if (!utils.isUndefined(config2[prop])) { if (!utils.isUndefined(config2[prop])) {
config[prop] = getMergedValue(undefined, config2[prop]); return getMergedValue(undefined, config2[prop]);
} }
}); }
utils.forEach(mergeDeepPropertiesKeys, mergeDeepProperties); // eslint-disable-next-line consistent-return
function defaultToConfig2(prop) {
utils.forEach(defaultToConfig2Keys, function defaultToConfig2(prop) {
if (!utils.isUndefined(config2[prop])) { if (!utils.isUndefined(config2[prop])) {
config[prop] = getMergedValue(undefined, config2[prop]); return getMergedValue(undefined, config2[prop]);
} else if (!utils.isUndefined(config1[prop])) { } else if (!utils.isUndefined(config1[prop])) {
config[prop] = getMergedValue(undefined, config1[prop]); return getMergedValue(undefined, config1[prop]);
} }
}); }
utils.forEach(directMergeKeys, function merge(prop) { // eslint-disable-next-line consistent-return
function mergeDirectKeys(prop) {
if (prop in config2) { if (prop in config2) {
config[prop] = getMergedValue(config1[prop], config2[prop]); return getMergedValue(config1[prop], config2[prop]);
} else if (prop in config1) { } else if (prop in config1) {
config[prop] = getMergedValue(undefined, config1[prop]); return getMergedValue(undefined, config1[prop]);
} }
}
var mergeMap = {
'url': valueFromConfig2,
'method': valueFromConfig2,
'data': valueFromConfig2,
'baseURL': defaultToConfig2,
'transformRequest': defaultToConfig2,
'transformResponse': defaultToConfig2,
'paramsSerializer': defaultToConfig2,
'timeout': defaultToConfig2,
'timeoutMessage': defaultToConfig2,
'withCredentials': defaultToConfig2,
'adapter': defaultToConfig2,
'responseType': defaultToConfig2,
'xsrfCookieName': defaultToConfig2,
'xsrfHeaderName': defaultToConfig2,
'onUploadProgress': defaultToConfig2,
'onDownloadProgress': defaultToConfig2,
'decompress': defaultToConfig2,
'maxContentLength': defaultToConfig2,
'maxBodyLength': defaultToConfig2,
'transport': defaultToConfig2,
'httpAgent': defaultToConfig2,
'httpsAgent': defaultToConfig2,
'cancelToken': defaultToConfig2,
'socketPath': defaultToConfig2,
'responseEncoding': defaultToConfig2,
'validateStatus': mergeDirectKeys
};
utils.forEach(Object.keys(config1).concat(Object.keys(config2)), function computeConfigValue(prop) {
var merge = mergeMap[prop] || mergeDeepProperties;
var configValue = merge(prop);
(utils.isUndefined(configValue) && merge !== mergeDirectKeys) || (config[prop] = configValue);
}); });
var axiosKeys = valueFromConfig2Keys
.concat(mergeDeepPropertiesKeys)
.concat(defaultToConfig2Keys)
.concat(directMergeKeys);
var otherKeys = Object
.keys(config1)
.concat(Object.keys(config2))
.filter(function filterAxiosKeys(key) {
return axiosKeys.indexOf(key) === -1;
});
utils.forEach(otherKeys, mergeDeepProperties);
return config; return config;
}; };
@@ -1189,7 +1292,7 @@ var defaults = {
}], }],
transformResponse: [function transformResponse(data) { transformResponse: [function transformResponse(data) {
var transitional = this.transitional; var transitional = this.transitional || defaults.transitional;
var silentJSONParsing = transitional && transitional.silentJSONParsing; var silentJSONParsing = transitional && transitional.silentJSONParsing;
var forcedJSONParsing = transitional && transitional.forcedJSONParsing; var forcedJSONParsing = transitional && transitional.forcedJSONParsing;
var strictJSONParsing = !silentJSONParsing && this.responseType === 'json'; var strictJSONParsing = !silentJSONParsing && this.responseType === 'json';
@@ -1224,12 +1327,12 @@ var defaults = {
validateStatus: function validateStatus(status) { validateStatus: function validateStatus(status) {
return status >= 200 && status < 300; return status >= 200 && status < 300;
} },
};
defaults.headers = { headers: {
common: { common: {
'Accept': 'application/json, text/plain, */*' 'Accept': 'application/json, text/plain, */*'
}
} }
}; };
@@ -1244,6 +1347,19 @@ utils.forEach(['post', 'put', 'patch'], function forEachMethodWithData(method) {
module.exports = defaults; module.exports = defaults;
/***/ }),
/***/ "./lib/env/data.js":
/*!*************************!*\
!*** ./lib/env/data.js ***!
\*************************/
/*! no static exports found */
/***/ (function(module, exports) {
module.exports = {
"version": "0.22.0"
};
/***/ }), /***/ }),
/***/ "./lib/helpers/bind.js": /***/ "./lib/helpers/bind.js":
@@ -1709,7 +1825,7 @@ module.exports = function spread(callback) {
"use strict"; "use strict";
var pkg = __webpack_require__(/*! ./../../package.json */ "./package.json"); var VERSION = __webpack_require__(/*! ../env/data */ "./lib/env/data.js").version;
var validators = {}; var validators = {};
@@ -1721,48 +1837,26 @@ var validators = {};
}); });
var deprecatedWarnings = {}; var deprecatedWarnings = {};
var currentVerArr = pkg.version.split('.');
/**
* Compare package versions
* @param {string} version
* @param {string?} thanVersion
* @returns {boolean}
*/
function isOlderVersion(version, thanVersion) {
var pkgVersionArr = thanVersion ? thanVersion.split('.') : currentVerArr;
var destVer = version.split('.');
for (var i = 0; i < 3; i++) {
if (pkgVersionArr[i] > destVer[i]) {
return true;
} else if (pkgVersionArr[i] < destVer[i]) {
return false;
}
}
return false;
}
/** /**
* Transitional option validator * Transitional option validator
* @param {function|boolean?} validator * @param {function|boolean?} validator - set to false if the transitional option has been removed
* @param {string?} version * @param {string?} version - deprecated version / removed since version
* @param {string} message * @param {string?} message - some message with additional info
* @returns {function} * @returns {function}
*/ */
validators.transitional = function transitional(validator, version, message) { validators.transitional = function transitional(validator, version, message) {
var isDeprecated = version && isOlderVersion(version);
function formatMessage(opt, desc) { function formatMessage(opt, desc) {
return '[Axios v' + pkg.version + '] Transitional option \'' + opt + '\'' + desc + (message ? '. ' + message : ''); return '[Axios v' + VERSION + '] Transitional option \'' + opt + '\'' + desc + (message ? '. ' + message : '');
} }
// eslint-disable-next-line func-names // eslint-disable-next-line func-names
return function(value, opt, opts) { return function(value, opt, opts) {
if (validator === false) { if (validator === false) {
throw new Error(formatMessage(opt, ' has been removed in ' + version)); throw new Error(formatMessage(opt, ' has been removed' + (version ? ' in ' + version : '')));
} }
if (isDeprecated && !deprecatedWarnings[opt]) { if (version && !deprecatedWarnings[opt]) {
deprecatedWarnings[opt] = true; deprecatedWarnings[opt] = true;
// eslint-disable-next-line no-console // eslint-disable-next-line no-console
console.warn( console.warn(
@@ -1808,7 +1902,6 @@ function assertOptions(options, schema, allowUnknown) {
} }
module.exports = { module.exports = {
isOlderVersion: isOlderVersion,
assertOptions: assertOptions, assertOptions: assertOptions,
validators: validators validators: validators
}; };
@@ -2175,17 +2268,6 @@ module.exports = {
}; };
/***/ }),
/***/ "./package.json":
/*!**********************!*\
!*** ./package.json ***!
\**********************/
/*! exports provided: name, version, description, main, scripts, repository, keywords, author, license, bugs, homepage, devDependencies, browser, jsdelivr, unpkg, typings, dependencies, bundlesize, default */
/***/ (function(module) {
module.exports = JSON.parse("{\"name\":\"axios\",\"version\":\"0.21.4\",\"description\":\"Promise based HTTP client for the browser and node.js\",\"main\":\"index.js\",\"scripts\":{\"test\":\"grunt test\",\"start\":\"node ./sandbox/server.js\",\"build\":\"NODE_ENV=production grunt build\",\"preversion\":\"npm test\",\"version\":\"npm run build && grunt version && git add -A dist && git add CHANGELOG.md bower.json package.json\",\"postversion\":\"git push && git push --tags\",\"examples\":\"node ./examples/server.js\",\"coveralls\":\"cat coverage/lcov.info | ./node_modules/coveralls/bin/coveralls.js\",\"fix\":\"eslint --fix lib/**/*.js\"},\"repository\":{\"type\":\"git\",\"url\":\"https://github.com/axios/axios.git\"},\"keywords\":[\"xhr\",\"http\",\"ajax\",\"promise\",\"node\"],\"author\":\"Matt Zabriskie\",\"license\":\"MIT\",\"bugs\":{\"url\":\"https://github.com/axios/axios/issues\"},\"homepage\":\"https://axios-http.com\",\"devDependencies\":{\"coveralls\":\"^3.0.0\",\"es6-promise\":\"^4.2.4\",\"grunt\":\"^1.3.0\",\"grunt-banner\":\"^0.6.0\",\"grunt-cli\":\"^1.2.0\",\"grunt-contrib-clean\":\"^1.1.0\",\"grunt-contrib-watch\":\"^1.0.0\",\"grunt-eslint\":\"^23.0.0\",\"grunt-karma\":\"^4.0.0\",\"grunt-mocha-test\":\"^0.13.3\",\"grunt-ts\":\"^6.0.0-beta.19\",\"grunt-webpack\":\"^4.0.2\",\"istanbul-instrumenter-loader\":\"^1.0.0\",\"jasmine-core\":\"^2.4.1\",\"karma\":\"^6.3.2\",\"karma-chrome-launcher\":\"^3.1.0\",\"karma-firefox-launcher\":\"^2.1.0\",\"karma-jasmine\":\"^1.1.1\",\"karma-jasmine-ajax\":\"^0.1.13\",\"karma-safari-launcher\":\"^1.0.0\",\"karma-sauce-launcher\":\"^4.3.6\",\"karma-sinon\":\"^1.0.5\",\"karma-sourcemap-loader\":\"^0.3.8\",\"karma-webpack\":\"^4.0.2\",\"load-grunt-tasks\":\"^3.5.2\",\"minimist\":\"^1.2.0\",\"mocha\":\"^8.2.1\",\"sinon\":\"^4.5.0\",\"terser-webpack-plugin\":\"^4.2.3\",\"typescript\":\"^4.0.5\",\"url-search-params\":\"^0.10.0\",\"webpack\":\"^4.44.2\",\"webpack-dev-server\":\"^3.11.0\"},\"browser\":{\"./lib/adapters/http.js\":\"./lib/adapters/xhr.js\"},\"jsdelivr\":\"dist/axios.min.js\",\"unpkg\":\"dist/axios.min.js\",\"typings\":\"./index.d.ts\",\"dependencies\":{\"follow-redirects\":\"^1.14.0\"},\"bundlesize\":[{\"path\":\"./dist/axios.min.js\",\"threshold\":\"5kB\"}]}");
/***/ }) /***/ })
/******/ }); /******/ });
+1 -1
View File
File diff suppressed because one or more lines are too long
+1 -2
View File
File diff suppressed because one or more lines are too long
+1 -1
View File
File diff suppressed because one or more lines are too long
Vendored
+2
View File
@@ -78,6 +78,7 @@ export interface AxiosRequestConfig<T = any> {
cancelToken?: CancelToken; cancelToken?: CancelToken;
decompress?: boolean; decompress?: boolean;
transitional?: TransitionalOptions transitional?: TransitionalOptions
signal?: AbortSignal;
} }
export interface AxiosResponse<T = never> { export interface AxiosResponse<T = never> {
@@ -162,6 +163,7 @@ export interface AxiosStatic extends AxiosInstance {
Cancel: CancelStatic; Cancel: CancelStatic;
CancelToken: CancelTokenStatic; CancelToken: CancelTokenStatic;
Axios: typeof Axios; Axios: typeof Axios;
readonly VERSION: string;
isCancel(value: any): boolean; isCancel(value: any): boolean;
all<T>(values: (T | Promise<T>)[]): Promise<T[]>; all<T>(values: (T | Promise<T>)[]): Promise<T[]>;
spread<T, R>(callback: (...args: T[]) => R): (array: T[]) => R; spread<T, R>(callback: (...args: T[]) => R): (array: T[]) => R;
+29 -7
View File
@@ -10,9 +10,11 @@ var httpFollow = require('follow-redirects').http;
var httpsFollow = require('follow-redirects').https; var httpsFollow = require('follow-redirects').https;
var url = require('url'); var url = require('url');
var zlib = require('zlib'); var zlib = require('zlib');
var pkg = require('./../../package.json'); var VERSION = require('./../env/data').version;
var createError = require('../core/createError'); var createError = require('../core/createError');
var enhanceError = require('../core/enhanceError'); var enhanceError = require('../core/enhanceError');
var defaults = require('../defaults');
var Cancel = require('../cancel/Cancel');
var isHttps = /https:?/; var isHttps = /https:?/;
@@ -44,10 +46,22 @@ function setProxy(options, proxy, location) {
/*eslint consistent-return:0*/ /*eslint consistent-return:0*/
module.exports = function httpAdapter(config) { module.exports = function httpAdapter(config) {
return new Promise(function dispatchHttpRequest(resolvePromise, rejectPromise) { return new Promise(function dispatchHttpRequest(resolvePromise, rejectPromise) {
var onCanceled;
function done() {
if (config.cancelToken) {
config.cancelToken.unsubscribe(onCanceled);
}
if (config.signal) {
config.signal.removeEventListener('abort', onCanceled);
}
}
var resolve = function resolve(value) { var resolve = function resolve(value) {
done();
resolvePromise(value); resolvePromise(value);
}; };
var reject = function reject(value) { var reject = function reject(value) {
done();
rejectPromise(value); rejectPromise(value);
}; };
var data = config.data; var data = config.data;
@@ -68,7 +82,7 @@ module.exports = function httpAdapter(config) {
// Otherwise, use specified value // Otherwise, use specified value
} else { } else {
// Only set header if it hasn't been set in config // Only set header if it hasn't been set in config
headers['User-Agent'] = 'axios/' + pkg.version; headers['User-Agent'] = 'axios/' + VERSION;
} }
if (data && !utils.isStream(data)) { if (data && !utils.isStream(data)) {
@@ -310,25 +324,33 @@ module.exports = function httpAdapter(config) {
// ClientRequest.setTimeout will be fired on the specify milliseconds, and can make sure that abort() will be fired after connect. // ClientRequest.setTimeout will be fired on the specify milliseconds, and can make sure that abort() will be fired after connect.
req.setTimeout(timeout, function handleRequestTimeout() { req.setTimeout(timeout, function handleRequestTimeout() {
req.abort(); req.abort();
var transitional = config.transitional || defaults.transitional;
reject(createError( reject(createError(
'timeout of ' + timeout + 'ms exceeded', 'timeout of ' + timeout + 'ms exceeded',
config, config,
config.transitional && config.transitional.clarifyTimeoutError ? 'ETIMEDOUT' : 'ECONNABORTED', transitional.clarifyTimeoutError ? 'ETIMEDOUT' : 'ECONNABORTED',
req req
)); ));
}); });
} }
if (config.cancelToken) { if (config.cancelToken || config.signal) {
// Handle cancellation // Handle cancellation
config.cancelToken.promise.then(function onCanceled(cancel) { // eslint-disable-next-line func-names
onCanceled = function(cancel) {
if (req.aborted) return; if (req.aborted) return;
req.abort(); req.abort();
reject(cancel); reject(!cancel || (cancel && cancel.type) ? new Cancel('canceled') : cancel);
}); };
config.cancelToken && config.cancelToken.subscribe(onCanceled);
if (config.signal) {
config.signal.aborted ? onCanceled() : config.signal.addEventListener('abort', onCanceled);
}
} }
// Send the request // Send the request
if (utils.isStream(data)) { if (utils.isStream(data)) {
data.on('error', function handleStreamError(err) { data.on('error', function handleStreamError(err) {
+31 -8
View File
@@ -8,12 +8,24 @@ var buildFullPath = require('../core/buildFullPath');
var parseHeaders = require('./../helpers/parseHeaders'); var parseHeaders = require('./../helpers/parseHeaders');
var isURLSameOrigin = require('./../helpers/isURLSameOrigin'); var isURLSameOrigin = require('./../helpers/isURLSameOrigin');
var createError = require('../core/createError'); var createError = require('../core/createError');
var defaults = require('../defaults');
var Cancel = require('../cancel/Cancel');
module.exports = function xhrAdapter(config) { module.exports = function xhrAdapter(config) {
return new Promise(function dispatchXhrRequest(resolve, reject) { return new Promise(function dispatchXhrRequest(resolve, reject) {
var requestData = config.data; var requestData = config.data;
var requestHeaders = config.headers; var requestHeaders = config.headers;
var responseType = config.responseType; var responseType = config.responseType;
var onCanceled;
function done() {
if (config.cancelToken) {
config.cancelToken.unsubscribe(onCanceled);
}
if (config.signal) {
config.signal.removeEventListener('abort', onCanceled);
}
}
if (utils.isFormData(requestData)) { if (utils.isFormData(requestData)) {
delete requestHeaders['Content-Type']; // Let the browser set it delete requestHeaders['Content-Type']; // Let the browser set it
@@ -51,7 +63,13 @@ module.exports = function xhrAdapter(config) {
request: request request: request
}; };
settle(resolve, reject, response); settle(function _resolve(value) {
resolve(value);
done();
}, function _reject(err) {
reject(err);
done();
}, response);
// Clean up request // Clean up request
request = null; request = null;
@@ -105,13 +123,14 @@ module.exports = function xhrAdapter(config) {
// Handle timeout // Handle timeout
request.ontimeout = function handleTimeout() { request.ontimeout = function handleTimeout() {
var timeoutErrorMessage = config.timeout ? 'timeout of ' + config.timeout + 'ms exceeded' : 'timeout exceeded'; var timeoutErrorMessage = config.timeout ? 'timeout of ' + config.timeout + 'ms exceeded' : 'timeout exceeded';
var transitional = config.transitional || defaults.transitional;
if (config.timeoutErrorMessage) { if (config.timeoutErrorMessage) {
timeoutErrorMessage = config.timeoutErrorMessage; timeoutErrorMessage = config.timeoutErrorMessage;
} }
reject(createError( reject(createError(
timeoutErrorMessage, timeoutErrorMessage,
config, config,
config.transitional && config.transitional.clarifyTimeoutError ? 'ETIMEDOUT' : 'ECONNABORTED', transitional.clarifyTimeoutError ? 'ETIMEDOUT' : 'ECONNABORTED',
request)); request));
// Clean up request // Clean up request
@@ -165,18 +184,22 @@ module.exports = function xhrAdapter(config) {
request.upload.addEventListener('progress', config.onUploadProgress); request.upload.addEventListener('progress', config.onUploadProgress);
} }
if (config.cancelToken) { if (config.cancelToken || config.signal) {
// Handle cancellation // Handle cancellation
config.cancelToken.promise.then(function onCanceled(cancel) { // eslint-disable-next-line func-names
onCanceled = function(cancel) {
if (!request) { if (!request) {
return; return;
} }
reject(!cancel || (cancel && cancel.type) ? new Cancel('canceled') : cancel);
request.abort(); request.abort();
reject(cancel);
// Clean up request
request = null; request = null;
}); };
config.cancelToken && config.cancelToken.subscribe(onCanceled);
if (config.signal) {
config.signal.aborted ? onCanceled() : config.signal.addEventListener('abort', onCanceled);
}
} }
if (!requestData) { if (!requestData) {
+1
View File
@@ -40,6 +40,7 @@ axios.Axios = Axios;
axios.Cancel = require('./cancel/Cancel'); axios.Cancel = require('./cancel/Cancel');
axios.CancelToken = require('./cancel/CancelToken'); axios.CancelToken = require('./cancel/CancelToken');
axios.isCancel = require('./cancel/isCancel'); axios.isCancel = require('./cancel/isCancel');
axios.VERSION = require('./env/data').version;
// Expose all/spread // Expose all/spread
axios.all = function all(promises) { axios.all = function all(promises) {
+62
View File
@@ -14,11 +14,42 @@ function CancelToken(executor) {
} }
var resolvePromise; var resolvePromise;
this.promise = new Promise(function promiseExecutor(resolve) { this.promise = new Promise(function promiseExecutor(resolve) {
resolvePromise = resolve; resolvePromise = resolve;
}); });
var token = this; var token = this;
// eslint-disable-next-line func-names
this.promise.then(function(cancel) {
if (!token._listeners) return;
var i;
var l = token._listeners.length;
for (i = 0; i < l; i++) {
token._listeners[i](cancel);
}
token._listeners = null;
});
// eslint-disable-next-line func-names
this.promise.then = function(onfulfilled) {
var _resolve;
// eslint-disable-next-line func-names
var promise = new Promise(function(resolve) {
token.subscribe(resolve);
_resolve = resolve;
}).then(onfulfilled);
promise.cancel = function reject() {
token.unsubscribe(_resolve);
};
return promise;
};
executor(function cancel(message) { executor(function cancel(message) {
if (token.reason) { if (token.reason) {
// Cancellation has already been requested // Cancellation has already been requested
@@ -39,6 +70,37 @@ CancelToken.prototype.throwIfRequested = function throwIfRequested() {
} }
}; };
/**
* Subscribe to the cancel signal
*/
CancelToken.prototype.subscribe = function subscribe(listener) {
if (this.reason) {
listener(this.reason);
return;
}
if (this._listeners) {
this._listeners.push(listener);
} else {
this._listeners = [listener];
}
};
/**
* Unsubscribe from the cancel signal
*/
CancelToken.prototype.unsubscribe = function unsubscribe(listener) {
if (!this._listeners) {
return;
}
var index = this._listeners.indexOf(listener);
if (index !== -1) {
this._listeners.splice(index, 1);
}
};
/** /**
* Returns an object that contains a new `CancelToken` and a function that, when called, * Returns an object that contains a new `CancelToken` and a function that, when called,
* cancels the `CancelToken`. * cancels the `CancelToken`.
+3 -3
View File
@@ -51,9 +51,9 @@ Axios.prototype.request = function request(config) {
if (transitional !== undefined) { if (transitional !== undefined) {
validator.assertOptions(transitional, { validator.assertOptions(transitional, {
silentJSONParsing: validators.transitional(validators.boolean, '1.0.0'), silentJSONParsing: validators.transitional(validators.boolean),
forcedJSONParsing: validators.transitional(validators.boolean, '1.0.0'), forcedJSONParsing: validators.transitional(validators.boolean),
clarifyTimeoutError: validators.transitional(validators.boolean, '1.0.0') clarifyTimeoutError: validators.transitional(validators.boolean)
}, false); }, false);
} }
+5
View File
@@ -4,6 +4,7 @@ var utils = require('./../utils');
var transformData = require('./transformData'); var transformData = require('./transformData');
var isCancel = require('../cancel/isCancel'); var isCancel = require('../cancel/isCancel');
var defaults = require('../defaults'); var defaults = require('../defaults');
var Cancel = require('../cancel/Cancel');
/** /**
* Throws a `Cancel` if cancellation has been requested. * Throws a `Cancel` if cancellation has been requested.
@@ -12,6 +13,10 @@ function throwIfCancellationRequested(config) {
if (config.cancelToken) { if (config.cancelToken) {
config.cancelToken.throwIfRequested(); config.cancelToken.throwIfRequested();
} }
if (config.signal && config.signal.aborted) {
throw new Cancel('canceled');
}
} }
/** /**
+51 -39
View File
@@ -15,17 +15,6 @@ module.exports = function mergeConfig(config1, config2) {
config2 = config2 || {}; config2 = config2 || {};
var config = {}; var config = {};
var valueFromConfig2Keys = ['url', 'method', 'data'];
var mergeDeepPropertiesKeys = ['headers', 'auth', 'proxy', 'params'];
var defaultToConfig2Keys = [
'baseURL', 'transformRequest', 'transformResponse', 'paramsSerializer',
'timeout', 'timeoutMessage', 'withCredentials', 'adapter', 'responseType', 'xsrfCookieName',
'xsrfHeaderName', 'onUploadProgress', 'onDownloadProgress', 'decompress',
'maxContentLength', 'maxBodyLength', 'maxRedirects', 'transport', 'httpAgent',
'httpsAgent', 'cancelToken', 'socketPath', 'responseEncoding'
];
var directMergeKeys = ['validateStatus'];
function getMergedValue(target, source) { function getMergedValue(target, source) {
if (utils.isPlainObject(target) && utils.isPlainObject(source)) { if (utils.isPlainObject(target) && utils.isPlainObject(source)) {
return utils.merge(target, source); return utils.merge(target, source);
@@ -37,51 +26,74 @@ module.exports = function mergeConfig(config1, config2) {
return source; return source;
} }
// eslint-disable-next-line consistent-return
function mergeDeepProperties(prop) { function mergeDeepProperties(prop) {
if (!utils.isUndefined(config2[prop])) { if (!utils.isUndefined(config2[prop])) {
config[prop] = getMergedValue(config1[prop], config2[prop]); return getMergedValue(config1[prop], config2[prop]);
} else if (!utils.isUndefined(config1[prop])) { } else if (!utils.isUndefined(config1[prop])) {
config[prop] = getMergedValue(undefined, config1[prop]); return getMergedValue(undefined, config1[prop]);
} }
} }
utils.forEach(valueFromConfig2Keys, function valueFromConfig2(prop) { // eslint-disable-next-line consistent-return
function valueFromConfig2(prop) {
if (!utils.isUndefined(config2[prop])) { if (!utils.isUndefined(config2[prop])) {
config[prop] = getMergedValue(undefined, config2[prop]); return getMergedValue(undefined, config2[prop]);
} }
}); }
utils.forEach(mergeDeepPropertiesKeys, mergeDeepProperties); // eslint-disable-next-line consistent-return
function defaultToConfig2(prop) {
utils.forEach(defaultToConfig2Keys, function defaultToConfig2(prop) {
if (!utils.isUndefined(config2[prop])) { if (!utils.isUndefined(config2[prop])) {
config[prop] = getMergedValue(undefined, config2[prop]); return getMergedValue(undefined, config2[prop]);
} else if (!utils.isUndefined(config1[prop])) { } else if (!utils.isUndefined(config1[prop])) {
config[prop] = getMergedValue(undefined, config1[prop]); return getMergedValue(undefined, config1[prop]);
} }
}); }
utils.forEach(directMergeKeys, function merge(prop) { // eslint-disable-next-line consistent-return
function mergeDirectKeys(prop) {
if (prop in config2) { if (prop in config2) {
config[prop] = getMergedValue(config1[prop], config2[prop]); return getMergedValue(config1[prop], config2[prop]);
} else if (prop in config1) { } else if (prop in config1) {
config[prop] = getMergedValue(undefined, config1[prop]); return getMergedValue(undefined, config1[prop]);
} }
}
var mergeMap = {
'url': valueFromConfig2,
'method': valueFromConfig2,
'data': valueFromConfig2,
'baseURL': defaultToConfig2,
'transformRequest': defaultToConfig2,
'transformResponse': defaultToConfig2,
'paramsSerializer': defaultToConfig2,
'timeout': defaultToConfig2,
'timeoutMessage': defaultToConfig2,
'withCredentials': defaultToConfig2,
'adapter': defaultToConfig2,
'responseType': defaultToConfig2,
'xsrfCookieName': defaultToConfig2,
'xsrfHeaderName': defaultToConfig2,
'onUploadProgress': defaultToConfig2,
'onDownloadProgress': defaultToConfig2,
'decompress': defaultToConfig2,
'maxContentLength': defaultToConfig2,
'maxBodyLength': defaultToConfig2,
'transport': defaultToConfig2,
'httpAgent': defaultToConfig2,
'httpsAgent': defaultToConfig2,
'cancelToken': defaultToConfig2,
'socketPath': defaultToConfig2,
'responseEncoding': defaultToConfig2,
'validateStatus': mergeDirectKeys
};
utils.forEach(Object.keys(config1).concat(Object.keys(config2)), function computeConfigValue(prop) {
var merge = mergeMap[prop] || mergeDeepProperties;
var configValue = merge(prop);
(utils.isUndefined(configValue) && merge !== mergeDirectKeys) || (config[prop] = configValue);
}); });
var axiosKeys = valueFromConfig2Keys
.concat(mergeDeepPropertiesKeys)
.concat(defaultToConfig2Keys)
.concat(directMergeKeys);
var otherKeys = Object
.keys(config1)
.concat(Object.keys(config2))
.filter(function filterAxiosKeys(key) {
return axiosKeys.indexOf(key) === -1;
});
utils.forEach(otherKeys, mergeDeepProperties);
return config; return config;
}; };
+6 -6
View File
@@ -79,7 +79,7 @@ var defaults = {
}], }],
transformResponse: [function transformResponse(data) { transformResponse: [function transformResponse(data) {
var transitional = this.transitional; var transitional = this.transitional || defaults.transitional;
var silentJSONParsing = transitional && transitional.silentJSONParsing; var silentJSONParsing = transitional && transitional.silentJSONParsing;
var forcedJSONParsing = transitional && transitional.forcedJSONParsing; var forcedJSONParsing = transitional && transitional.forcedJSONParsing;
var strictJSONParsing = !silentJSONParsing && this.responseType === 'json'; var strictJSONParsing = !silentJSONParsing && this.responseType === 'json';
@@ -114,12 +114,12 @@ var defaults = {
validateStatus: function validateStatus(status) { validateStatus: function validateStatus(status) {
return status >= 200 && status < 300; return status >= 200 && status < 300;
} },
};
defaults.headers = { headers: {
common: { common: {
'Accept': 'application/json, text/plain, */*' 'Accept': 'application/json, text/plain, */*'
}
} }
}; };
+3
View File
@@ -0,0 +1,3 @@
# axios // env
The `data.js` file is updated automatically when the package version is upgrading. Please do not edit it manually.
+3
View File
@@ -0,0 +1,3 @@
module.exports = {
"version": "0.22.0"
};
+7 -30
View File
@@ -1,6 +1,6 @@
'use strict'; 'use strict';
var pkg = require('./../../package.json'); var VERSION = require('../env/data').version;
var validators = {}; var validators = {};
@@ -12,48 +12,26 @@ var validators = {};
}); });
var deprecatedWarnings = {}; var deprecatedWarnings = {};
var currentVerArr = pkg.version.split('.');
/**
* Compare package versions
* @param {string} version
* @param {string?} thanVersion
* @returns {boolean}
*/
function isOlderVersion(version, thanVersion) {
var pkgVersionArr = thanVersion ? thanVersion.split('.') : currentVerArr;
var destVer = version.split('.');
for (var i = 0; i < 3; i++) {
if (pkgVersionArr[i] > destVer[i]) {
return true;
} else if (pkgVersionArr[i] < destVer[i]) {
return false;
}
}
return false;
}
/** /**
* Transitional option validator * Transitional option validator
* @param {function|boolean?} validator * @param {function|boolean?} validator - set to false if the transitional option has been removed
* @param {string?} version * @param {string?} version - deprecated version / removed since version
* @param {string} message * @param {string?} message - some message with additional info
* @returns {function} * @returns {function}
*/ */
validators.transitional = function transitional(validator, version, message) { validators.transitional = function transitional(validator, version, message) {
var isDeprecated = version && isOlderVersion(version);
function formatMessage(opt, desc) { function formatMessage(opt, desc) {
return '[Axios v' + pkg.version + '] Transitional option \'' + opt + '\'' + desc + (message ? '. ' + message : ''); return '[Axios v' + VERSION + '] Transitional option \'' + opt + '\'' + desc + (message ? '. ' + message : '');
} }
// eslint-disable-next-line func-names // eslint-disable-next-line func-names
return function(value, opt, opts) { return function(value, opt, opts) {
if (validator === false) { if (validator === false) {
throw new Error(formatMessage(opt, ' has been removed in ' + version)); throw new Error(formatMessage(opt, ' has been removed' + (version ? ' in ' + version : '')));
} }
if (isDeprecated && !deprecatedWarnings[opt]) { if (version && !deprecatedWarnings[opt]) {
deprecatedWarnings[opt] = true; deprecatedWarnings[opt] = true;
// eslint-disable-next-line no-console // eslint-disable-next-line no-console
console.warn( console.warn(
@@ -99,7 +77,6 @@ function assertOptions(options, schema, allowUnknown) {
} }
module.exports = { module.exports = {
isOlderVersion: isOlderVersion,
assertOptions: assertOptions, assertOptions: assertOptions,
validators: validators validators: validators
}; };
+5 -4
View File
@@ -1,6 +1,6 @@
{ {
"name": "axios", "name": "axios",
"version": "0.21.4", "version": "0.22.0",
"description": "Promise based HTTP client for the browser and node.js", "description": "Promise based HTTP client for the browser and node.js",
"main": "index.js", "main": "index.js",
"types": "index.d.ts", "types": "index.d.ts",
@@ -8,8 +8,8 @@
"test": "grunt test", "test": "grunt test",
"start": "node ./sandbox/server.js", "start": "node ./sandbox/server.js",
"build": "NODE_ENV=production grunt build", "build": "NODE_ENV=production grunt build",
"preversion": "npm test", "preversion": "grunt version && npm test",
"version": "npm run build && grunt version && git add -A dist && git add CHANGELOG.md bower.json package.json", "version": "npm run build && git add -A dist && git add CHANGELOG.md bower.json package.json",
"postversion": "git push && git push --tags", "postversion": "git push && git push --tags",
"examples": "node ./examples/server.js", "examples": "node ./examples/server.js",
"coveralls": "cat coverage/lcov.info | ./node_modules/coveralls/bin/coveralls.js", "coveralls": "cat coverage/lcov.info | ./node_modules/coveralls/bin/coveralls.js",
@@ -33,6 +33,7 @@
}, },
"homepage": "https://axios-http.com", "homepage": "https://axios-http.com",
"devDependencies": { "devDependencies": {
"abortcontroller-polyfill": "^1.5.0",
"coveralls": "^3.0.0", "coveralls": "^3.0.0",
"es6-promise": "^4.2.4", "es6-promise": "^4.2.4",
"grunt": "^1.3.0", "grunt": "^1.3.0",
@@ -74,7 +75,7 @@
"unpkg": "dist/axios.min.js", "unpkg": "dist/axios.min.js",
"typings": "./index.d.ts", "typings": "./index.d.ts",
"dependencies": { "dependencies": {
"follow-redirects": "^1.14.0" "follow-redirects": "^1.14.4"
}, },
"bundlesize": [ "bundlesize": [
{ {
+40 -11
View File
@@ -1,5 +1,8 @@
var Cancel = axios.Cancel; var Cancel = axios.Cancel;
var CancelToken = axios.CancelToken; var CancelToken = axios.CancelToken;
var _AbortController = require('abortcontroller-polyfill/dist/cjs-ponyfill.js').AbortController;
var AbortController = typeof AbortController === 'function' ? AbortController : _AbortController;
describe('cancel', function() { describe('cancel', function() {
beforeEach(function() { beforeEach(function() {
@@ -11,12 +14,12 @@ describe('cancel', function() {
}); });
describe('when called before sending request', function() { describe('when called before sending request', function() {
it('rejects Promise with a Cancel object', function (done) { it('rejects Promise with a Cancel object', function(done) {
var source = CancelToken.source(); var source = CancelToken.source();
source.cancel('Operation has been canceled.'); source.cancel('Operation has been canceled.');
axios.get('/foo', { axios.get('/foo', {
cancelToken: source.token cancelToken: source.token
}).catch(function (thrown) { }).catch(function(thrown) {
expect(thrown).toEqual(jasmine.any(Cancel)); expect(thrown).toEqual(jasmine.any(Cancel));
expect(thrown.message).toBe('Operation has been canceled.'); expect(thrown.message).toBe('Operation has been canceled.');
done(); done();
@@ -25,17 +28,17 @@ describe('cancel', function() {
}); });
describe('when called after request has been sent', function() { describe('when called after request has been sent', function() {
it('rejects Promise with a Cancel object', function (done) { it('rejects Promise with a Cancel object', function(done) {
var source = CancelToken.source(); var source = CancelToken.source();
axios.get('/foo/bar', { axios.get('/foo/bar', {
cancelToken: source.token cancelToken: source.token
}).catch(function (thrown) { }).catch(function(thrown) {
expect(thrown).toEqual(jasmine.any(Cancel)); expect(thrown).toEqual(jasmine.any(Cancel));
expect(thrown.message).toBe('Operation has been canceled.'); expect(thrown.message).toBe('Operation has been canceled.');
done(); done();
}); });
getAjaxRequest().then(function (request) { getAjaxRequest().then(function(request) {
// call cancel() when the request has been sent, but a response has not been received // call cancel() when the request has been sent, but a response has not been received
source.cancel('Operation has been canceled.'); source.cancel('Operation has been canceled.');
request.respondWith({ request.respondWith({
@@ -45,7 +48,7 @@ describe('cancel', function() {
}); });
}); });
it('calls abort on request object', function (done) { it('calls abort on request object', function(done) {
var source = CancelToken.source(); var source = CancelToken.source();
var request; var request;
axios.get('/foo/bar', { axios.get('/foo/bar', {
@@ -56,7 +59,7 @@ describe('cancel', function() {
done(); done();
}); });
getAjaxRequest().then(function (req) { getAjaxRequest().then(function(req) {
// call cancel() when the request has been sent, but a response has not been received // call cancel() when the request has been sent, but a response has not been received
source.cancel(); source.cancel();
request = req; request = req;
@@ -66,19 +69,19 @@ describe('cancel', function() {
describe('when called after response has been received', function() { describe('when called after response has been received', function() {
// https://github.com/axios/axios/issues/482 // https://github.com/axios/axios/issues/482
it('does not cause unhandled rejection', function (done) { it('does not cause unhandled rejection', function(done) {
var source = CancelToken.source(); var source = CancelToken.source();
axios.get('/foo', { axios.get('/foo', {
cancelToken: source.token cancelToken: source.token
}).then(function () { }).then(function() {
window.addEventListener('unhandledrejection', function () { window.addEventListener('unhandledrejection', function() {
done.fail('Unhandled rejection.'); done.fail('Unhandled rejection.');
}); });
source.cancel(); source.cancel();
setTimeout(done, 100); setTimeout(done, 100);
}); });
getAjaxRequest().then(function (request) { getAjaxRequest().then(function(request) {
request.respondWith({ request.respondWith({
status: 200, status: 200,
responseText: 'OK' responseText: 'OK'
@@ -86,4 +89,30 @@ describe('cancel', function() {
}); });
}); });
}); });
it('it should support cancellation using AbortController signal', function(done) {
var controller = new AbortController();
axios.get('/foo/bar', {
signal: controller.signal
}).then(function() {
done.fail('Has not been canceled');
},
function(thrown) {
expect(thrown).toEqual(jasmine.any(Cancel));
done();
}
);
getAjaxRequest().then(function (request) {
// call cancel() when the request has been sent, but a response has not been received
controller.abort();
setTimeout(function(){
request.respondWith({
status: 200,
responseText: 'OK'
});
}, 0);
});
});
}); });
+3 -18
View File
@@ -2,23 +2,8 @@
var validator = require('../../../lib/helpers/validator'); var validator = require('../../../lib/helpers/validator');
describe('validator::isOlderVersion', function () { describe('validator::assertOptions', function() {
it('should return true if dest version is older than the package version', function () { it('should throw only if unknown an option was passed', function() {
expect(validator.isOlderVersion('0.0.1', '1.0.0')).toEqual(true);
expect(validator.isOlderVersion('0.0.1', '0.1.0')).toEqual(true);
expect(validator.isOlderVersion('0.0.1', '0.0.1')).toEqual(false);
expect(validator.isOlderVersion('100.0.0', '1.0.0')).toEqual(false);
expect(validator.isOlderVersion('100.0.0', '0.1.0')).toEqual(false);
expect(validator.isOlderVersion('100.0.0', '0.0.1')).toEqual(false);
expect(validator.isOlderVersion('0.10000.0', '1000.0.1')).toEqual(true);
});
});
describe('validator::assertOptions', function () {
it('should throw only if unknown an option was passed', function () {
expect(function() { expect(function() {
validator.assertOptions({ validator.assertOptions({
x: true x: true
@@ -37,7 +22,7 @@ describe('validator::assertOptions', function () {
}).not.toThrow(new Error('Unknown option x')); }).not.toThrow(new Error('Unknown option x'));
}); });
it('should throw TypeError only if option type doesn\'t match', function () { it('should throw TypeError only if option type doesn\'t match', function() {
expect(function() { expect(function() {
validator.assertOptions({ validator.assertOptions({
x: 123 x: 123
+1
View File
@@ -20,6 +20,7 @@ describe('instance', function () {
'all', 'all',
'spread', 'spread',
'isAxiosError', 'isAxiosError',
'VERSION',
'default'].indexOf(prop) > -1) { 'default'].indexOf(prop) > -1) {
continue; continue;
} }
+1 -1
View File
@@ -953,7 +953,7 @@ describe('supports http with nodejs', function () {
axios.get('http://localhost:4444/', { axios.get('http://localhost:4444/', {
cancelToken: source.token cancelToken: source.token
}).catch(function (thrown) { }).catch(function (thrown) {
assert.ok(thrown instanceof axios.Cancel, 'Promise must be rejected with a Cancel obejct'); assert.ok(thrown instanceof axios.Cancel, 'Promise must be rejected with a Cancel object');
assert.equal(thrown.message, 'Operation has been canceled.'); assert.equal(thrown.message, 'Operation has been canceled.');
done(); done();
}); });