mirror of
https://github.com/tenrok/axios.git
synced 2026-06-08 17:22:34 +03:00
Merge branch 'master' into master
This commit is contained in:
+124
-121
@@ -1,148 +1,151 @@
|
||||
// eslint-disable-next-line strict
|
||||
module.exports = {
|
||||
"globals": {
|
||||
"console": true,
|
||||
"module": true,
|
||||
"require": true
|
||||
'globals': {
|
||||
'console': true,
|
||||
'module': true,
|
||||
'require': true
|
||||
},
|
||||
"env": {
|
||||
"browser": true,
|
||||
"node": true
|
||||
'env': {
|
||||
'browser': true,
|
||||
'node': true
|
||||
},
|
||||
"rules": {
|
||||
/**
|
||||
'rules': {
|
||||
/**
|
||||
* Strict mode
|
||||
*/
|
||||
"strict": [2, "global"], // http://eslint.org/docs/rules/strict
|
||||
'strict': [2, 'global'], // http://eslint.org/docs/rules/strict
|
||||
|
||||
/**
|
||||
/**
|
||||
* Variables
|
||||
*/
|
||||
"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-unused-vars": [2, { // http://eslint.org/docs/rules/no-unused-vars
|
||||
"vars": "local",
|
||||
"args": "after-used"
|
||||
'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-unused-vars': [2, { // http://eslint.org/docs/rules/no-unused-vars
|
||||
'vars': 'local',
|
||||
'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
|
||||
*/
|
||||
"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-console": 1, // http://eslint.org/docs/rules/no-console
|
||||
"no-debugger": 1, // http://eslint.org/docs/rules/no-debugger
|
||||
"no-alert": 1, // http://eslint.org/docs/rules/no-alert
|
||||
"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-duplicate-case": 2, // http://eslint.org/docs/rules/no-duplicate-case
|
||||
"no-empty": 2, // http://eslint.org/docs/rules/no-empty
|
||||
"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-semi": 2, // http://eslint.org/docs/rules/no-extra-semi
|
||||
"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-invalid-regexp": 2, // http://eslint.org/docs/rules/no-invalid-regexp
|
||||
"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-sparse-arrays": 2, // http://eslint.org/docs/rules/no-sparse-arrays
|
||||
"no-unreachable": 2, // http://eslint.org/docs/rules/no-unreachable
|
||||
"use-isnan": 2, // http://eslint.org/docs/rules/use-isnan
|
||||
"block-scoped-var": 2, // http://eslint.org/docs/rules/block-scoped-var
|
||||
'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-console': 1, // http://eslint.org/docs/rules/no-console
|
||||
'no-debugger': 1, // http://eslint.org/docs/rules/no-debugger
|
||||
'no-alert': 1, // http://eslint.org/docs/rules/no-alert
|
||||
'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-duplicate-case': 2, // http://eslint.org/docs/rules/no-duplicate-case
|
||||
'no-empty': 2, // http://eslint.org/docs/rules/no-empty
|
||||
'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-semi': 2, // http://eslint.org/docs/rules/no-extra-semi
|
||||
'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-invalid-regexp': 2, // http://eslint.org/docs/rules/no-invalid-regexp
|
||||
'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-sparse-arrays': 2, // http://eslint.org/docs/rules/no-sparse-arrays
|
||||
'no-unreachable': 2, // http://eslint.org/docs/rules/no-unreachable
|
||||
'use-isnan': 2, // http://eslint.org/docs/rules/use-isnan
|
||||
'block-scoped-var': 2, // http://eslint.org/docs/rules/block-scoped-var
|
||||
|
||||
/**
|
||||
/**
|
||||
* Best practices
|
||||
*/
|
||||
"consistent-return": 2, // http://eslint.org/docs/rules/consistent-return
|
||||
"curly": [2, "multi-line"], // http://eslint.org/docs/rules/curly
|
||||
"default-case": 2, // http://eslint.org/docs/rules/default-case
|
||||
"dot-notation": [2, { // http://eslint.org/docs/rules/dot-notation
|
||||
"allowKeywords": true
|
||||
'consistent-return': 2, // http://eslint.org/docs/rules/consistent-return
|
||||
'curly': [2, 'multi-line'], // http://eslint.org/docs/rules/curly
|
||||
'default-case': 2, // http://eslint.org/docs/rules/default-case
|
||||
'dot-notation': [2, { // http://eslint.org/docs/rules/dot-notation
|
||||
'allowKeywords': true
|
||||
}],
|
||||
"eqeqeq": 2, // http://eslint.org/docs/rules/eqeqeq
|
||||
"guard-for-in": 2, // http://eslint.org/docs/rules/guard-for-in
|
||||
"no-caller": 2, // http://eslint.org/docs/rules/no-caller
|
||||
"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-eval": 2, // http://eslint.org/docs/rules/no-eval
|
||||
"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-fallthrough": 2, // http://eslint.org/docs/rules/no-fallthrough
|
||||
"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-lone-blocks": 2, // http://eslint.org/docs/rules/no-lone-blocks
|
||||
"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-native-reassign": 2, // http://eslint.org/docs/rules/no-native-reassign
|
||||
"no-new": 2, // http://eslint.org/docs/rules/no-new
|
||||
"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-octal": 2, // http://eslint.org/docs/rules/no-octal
|
||||
"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-proto": 2, // http://eslint.org/docs/rules/no-proto
|
||||
"no-redeclare": 2, // http://eslint.org/docs/rules/no-redeclare
|
||||
"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-self-compare": 2, // http://eslint.org/docs/rules/no-self-compare
|
||||
"no-sequences": 2, // http://eslint.org/docs/rules/no-sequences
|
||||
"no-throw-literal": 2, // http://eslint.org/docs/rules/no-throw-literal
|
||||
"no-with": 2, // http://eslint.org/docs/rules/no-with
|
||||
"radix": 2, // http://eslint.org/docs/rules/radix
|
||||
"vars-on-top": 0, // http://eslint.org/docs/rules/vars-on-top
|
||||
"wrap-iife": [2, "any"], // http://eslint.org/docs/rules/wrap-iife
|
||||
"yoda": 2, // http://eslint.org/docs/rules/yoda
|
||||
'eqeqeq': 2, // http://eslint.org/docs/rules/eqeqeq
|
||||
'guard-for-in': 2, // http://eslint.org/docs/rules/guard-for-in
|
||||
'no-caller': 2, // http://eslint.org/docs/rules/no-caller
|
||||
'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-eval': 2, // http://eslint.org/docs/rules/no-eval
|
||||
'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-fallthrough': 2, // http://eslint.org/docs/rules/no-fallthrough
|
||||
'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-lone-blocks': 2, // http://eslint.org/docs/rules/no-lone-blocks
|
||||
'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-native-reassign': 2, // http://eslint.org/docs/rules/no-native-reassign
|
||||
'no-new': 2, // http://eslint.org/docs/rules/no-new
|
||||
'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-octal': 2, // http://eslint.org/docs/rules/no-octal
|
||||
'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-proto': 2, // http://eslint.org/docs/rules/no-proto
|
||||
'no-redeclare': 2, // http://eslint.org/docs/rules/no-redeclare
|
||||
'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-self-compare': 2, // http://eslint.org/docs/rules/no-self-compare
|
||||
'no-sequences': 2, // http://eslint.org/docs/rules/no-sequences
|
||||
'no-throw-literal': 2, // http://eslint.org/docs/rules/no-throw-literal
|
||||
'no-with': 2, // http://eslint.org/docs/rules/no-with
|
||||
'radix': 2, // http://eslint.org/docs/rules/radix
|
||||
'vars-on-top': 0, // http://eslint.org/docs/rules/vars-on-top
|
||||
'wrap-iife': [2, 'any'], // http://eslint.org/docs/rules/wrap-iife
|
||||
'yoda': 2, // http://eslint.org/docs/rules/yoda
|
||||
|
||||
/**
|
||||
/**
|
||||
* Style
|
||||
*/
|
||||
"indent": [2, 2], // http://eslint.org/docs/rules/indent
|
||||
"brace-style": [2, // http://eslint.org/docs/rules/brace-style
|
||||
"1tbs", {
|
||||
"allowSingleLine": true
|
||||
}],
|
||||
"quotes": [
|
||||
2, "single", "avoid-escape" // http://eslint.org/docs/rules/quotes
|
||||
'indent': [2, 2], // http://eslint.org/docs/rules/indent
|
||||
'brace-style': [2, // http://eslint.org/docs/rules/brace-style
|
||||
'1tbs', {
|
||||
'allowSingleLine': true
|
||||
}],
|
||||
'quotes': [
|
||||
2, 'single', 'avoid-escape' // http://eslint.org/docs/rules/quotes
|
||||
],
|
||||
"camelcase": [2, { // http://eslint.org/docs/rules/camelcase
|
||||
"properties": "never"
|
||||
'camelcase': [2, { // http://eslint.org/docs/rules/camelcase
|
||||
'properties': 'never'
|
||||
}],
|
||||
"comma-spacing": [2, { // http://eslint.org/docs/rules/comma-spacing
|
||||
"before": false,
|
||||
"after": true
|
||||
'comma-spacing': [2, { // http://eslint.org/docs/rules/comma-spacing
|
||||
'before': false,
|
||||
'after': true
|
||||
}],
|
||||
"comma-style": [2, "last"], // http://eslint.org/docs/rules/comma-style
|
||||
"eol-last": 2, // http://eslint.org/docs/rules/eol-last
|
||||
"func-names": 1, // http://eslint.org/docs/rules/func-names
|
||||
"key-spacing": [2, { // http://eslint.org/docs/rules/key-spacing
|
||||
"beforeColon": false,
|
||||
"afterColon": true
|
||||
'comma-style': [2, 'last'], // http://eslint.org/docs/rules/comma-style
|
||||
'eol-last': 2, // http://eslint.org/docs/rules/eol-last
|
||||
'func-names': 1, // http://eslint.org/docs/rules/func-names
|
||||
'key-spacing': [2, { // http://eslint.org/docs/rules/key-spacing
|
||||
'beforeColon': false,
|
||||
'afterColon': true
|
||||
}],
|
||||
"new-cap": [2, { // http://eslint.org/docs/rules/new-cap
|
||||
"newIsCap": true
|
||||
'new-cap': [2, { // http://eslint.org/docs/rules/new-cap
|
||||
'newIsCap': true
|
||||
}],
|
||||
"no-multiple-empty-lines": [2, { // http://eslint.org/docs/rules/no-multiple-empty-lines
|
||||
"max": 2
|
||||
'no-multiple-empty-lines': [2, { // http://eslint.org/docs/rules/no-multiple-empty-lines
|
||||
'max': 2
|
||||
}],
|
||||
"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-spaced-func": 2, // http://eslint.org/docs/rules/no-spaced-func
|
||||
"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-underscore-dangle": 0, // http://eslint.org/docs/rules/no-underscore-dangle
|
||||
"one-var": [2, "never"], // http://eslint.org/docs/rules/one-var
|
||||
"padded-blocks": [2, "never"], // http://eslint.org/docs/rules/padded-blocks
|
||||
"semi": [2, "always"], // http://eslint.org/docs/rules/semi
|
||||
"semi-spacing": [2, { // http://eslint.org/docs/rules/semi-spacing
|
||||
"before": false,
|
||||
"after": true
|
||||
'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-spaced-func': 2, // http://eslint.org/docs/rules/no-spaced-func
|
||||
'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-underscore-dangle': 0, // http://eslint.org/docs/rules/no-underscore-dangle
|
||||
'one-var': [2, 'never'], // http://eslint.org/docs/rules/one-var
|
||||
'padded-blocks': [2, 'never'], // http://eslint.org/docs/rules/padded-blocks
|
||||
'semi': [2, 'always'], // http://eslint.org/docs/rules/semi
|
||||
'semi-spacing': [2, { // http://eslint.org/docs/rules/semi-spacing
|
||||
'before': false,
|
||||
'after': true
|
||||
}],
|
||||
"keyword-spacing": 2, // http://eslint.org/docs/rules/keyword-spacing
|
||||
"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-infix-ops": 2, // http://eslint.org/docs/rules/space-infix-ops
|
||||
"spaced-comment": [2, "always", {// http://eslint.org/docs/rules/spaced-comment
|
||||
"markers": ["global", "eslint"]
|
||||
'keyword-spacing': 2, // http://eslint.org/docs/rules/keyword-spacing
|
||||
'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-infix-ops': 2, // http://eslint.org/docs/rules/space-infix-ops
|
||||
'spaced-comment': [2, 'always', {// http://eslint.org/docs/rules/spaced-comment
|
||||
'markers': ['global', 'eslint']
|
||||
}]
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
'ignorePatterns': ['**/env/data.js']
|
||||
};
|
||||
|
||||
@@ -0,0 +1 @@
|
||||
open_collective: axios
|
||||
@@ -0,0 +1,24 @@
|
||||
name: ci
|
||||
|
||||
on:
|
||||
push:
|
||||
branches: [master, 'release/*', dev]
|
||||
pull_request:
|
||||
branches: [master, 'release/*', dev]
|
||||
|
||||
jobs:
|
||||
build:
|
||||
runs-on: ubuntu-latest
|
||||
|
||||
strategy:
|
||||
matrix:
|
||||
node-version: [12.x, 14.x, 16.x]
|
||||
|
||||
steps:
|
||||
- uses: actions/checkout@v2
|
||||
- name: Setup node
|
||||
uses: actions/setup-node@v2
|
||||
with:
|
||||
node-version: ${{ matrix.node-version }}
|
||||
- run: npm install
|
||||
- run: npm test
|
||||
@@ -8,3 +8,4 @@ coverage/
|
||||
test/typescript/axios.js*
|
||||
sauce_connect.log
|
||||
package-lock.json
|
||||
yarn.lock
|
||||
+158
-6
@@ -1,18 +1,170 @@
|
||||
# Changelog
|
||||
|
||||
### 0.24.0 (October 25, 2021)
|
||||
|
||||
Breaking changes:
|
||||
- Revert: change type of AxiosResponse to any, please read lengthy discussion here: ([#4141](https://github.com/axios/axios/issues/4141)) pull request: ([#4186](https://github.com/axios/axios/pull/4186))
|
||||
|
||||
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)
|
||||
- [Rodry](https://github.com/ImRodry)
|
||||
- [Remco Haszing](https://github.com/remcohaszing)
|
||||
- [Isaiah Thomason](https://github.com/ITenthusiasm)
|
||||
|
||||
### 0.23.0 (October 12, 2021)
|
||||
|
||||
Breaking changes:
|
||||
- Distinguish request and response data types ([#4116](https://github.com/axios/axios/pull/4116))
|
||||
- Change never type to unknown ([#4142](https://github.com/axios/axios/pull/4142))
|
||||
- Fixed TransitionalOptions typings ([#4147](https://github.com/axios/axios/pull/4147))
|
||||
|
||||
Fixes and Functionality:
|
||||
- Adding globalObject: 'this' to webpack config ([#3176](https://github.com/axios/axios/pull/3176))
|
||||
- Adding insecureHTTPParser type to AxiosRequestConfig ([#4066](https://github.com/axios/axios/pull/4066))
|
||||
- Fix missing semicolon in typings ([#4115](https://github.com/axios/axios/pull/4115))
|
||||
- Fix response headers types ([#4136](https://github.com/axios/axios/pull/4136))
|
||||
|
||||
Internal and Tests:
|
||||
- Improve timeout error when timeout is browser default ([#3209](https://github.com/axios/axios/pull/3209))
|
||||
- Fix node version on CI ([#4069](https://github.com/axios/axios/pull/4069))
|
||||
- Added testing to TypeScript portion of project ([#4140](https://github.com/axios/axios/pull/4140))
|
||||
|
||||
Documentation:
|
||||
- Rename Angular to AngularJS ([#4114](https://github.com/axios/axios/pull/4114))
|
||||
|
||||
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)
|
||||
- [Evan-Finkelstein](https://github.com/Evan-Finkelstein)
|
||||
- [Paweł Szymański](https://github.com/Jezorko)
|
||||
- [Dobes Vandermeer](https://github.com/dobesv)
|
||||
- [Claas Augner](https://github.com/caugner)
|
||||
- [Remco Haszing](https://github.com/remcohaszing)
|
||||
- [Evgeniy](https://github.com/egmen)
|
||||
- [Dmitriy Mozgovoy](https://github.com/DigitalBrainJS)
|
||||
|
||||
### 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)
|
||||
|
||||
Fixes and Functionality:
|
||||
- Fixing JSON transform when data is stringified. Providing backward compatability and complying to the JSON RFC standard ([#4020](https://github.com/axios/axios/pull/4020))
|
||||
|
||||
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)
|
||||
- [Guillaume Fortaine](https://github.com/gfortaine)
|
||||
- [Yusuke Kawasaki](https://github.com/kawanet)
|
||||
- [Dmitriy Mozgovoy](https://github.com/DigitalBrainJS)
|
||||
|
||||
### 0.21.3 (September 4, 2021)
|
||||
|
||||
Fixes and Functionality:
|
||||
- Fixing response interceptor not being called when request interceptor is attached ([#4013](https://github.com/axios/axios/pull/4013))
|
||||
|
||||
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)
|
||||
- [Julian Hollmann](https://github.com/nerdbeere)
|
||||
|
||||
### 0.21.2 (September 4, 2021)
|
||||
|
||||
Fixes and Functionality:
|
||||
|
||||
- Updating axios requests to be delayed by pre-emptive promise creation ([#2702](https://github.com/axios/axios/pull/2702))
|
||||
- Adding "synchronous" and "runWhen" options to interceptors api ([#2702](https://github.com/axios/axios/pull/2702))
|
||||
- Updating of transformResponse ([#3377](https://github.com/axios/axios/pull/3377))
|
||||
- Adding ability to omit User-Agent header ([#3703](https://github.com/axios/axios/pull/3703))
|
||||
- Adding multiple JSON improvements ([#3688](https://github.com/axios/axios/pull/3688), [#3763](https://github.com/axios/axios/pull/3763))
|
||||
- Fixing quadratic runtime and extra memory usage when setting a maxContentLength ([#3738](https://github.com/axios/axios/pull/3738))
|
||||
- Adding parseInt to config.timeout ([#3781](https://github.com/axios/axios/pull/3781))
|
||||
- Adding custom return type support to interceptor ([#3783](https://github.com/axios/axios/pull/3783))
|
||||
- Adding security fix for ReDoS vulnerability ([#3980](https://github.com/axios/axios/pull/3980))
|
||||
|
||||
Internal and Tests:
|
||||
|
||||
- Updating build dev dependancies ([#3401](https://github.com/axios/axios/pull/3401))
|
||||
- Fixing builds running on Travis CI ([#3538](https://github.com/axios/axios/pull/3538))
|
||||
- Updating follow rediect version ([#3694](https://github.com/axios/axios/pull/3694), [#3771](https://github.com/axios/axios/pull/3771))
|
||||
- Updating karma sauce launcher to fix failing sauce tests ([#3712](https://github.com/axios/axios/pull/3712), [#3717](https://github.com/axios/axios/pull/3717))
|
||||
- Updating content-type header for application/json to not contain charset field, according do RFC 8259 ([#2154](https://github.com/axios/axios/pull/2154))
|
||||
- Fixing tests by bumping karma-sauce-launcher version ([#3813](https://github.com/axios/axios/pull/3813))
|
||||
- Changing testing process from Travis CI to GitHub Actions ([#3938](https://github.com/axios/axios/pull/3938))
|
||||
|
||||
Documentation:
|
||||
|
||||
- Updating documentation around the use of `AUTH_TOKEN` with multiple domain endpoints ([#3539](https://github.com/axios/axios/pull/3539))
|
||||
- Remove duplication of item in changelog ([#3523](https://github.com/axios/axios/pull/3523))
|
||||
- Fixing gramatical errors ([#2642](https://github.com/axios/axios/pull/2642))
|
||||
- Fixing spelling error ([#3567](https://github.com/axios/axios/pull/3567))
|
||||
- Moving gitpod metion ([#2637](https://github.com/axios/axios/pull/2637))
|
||||
- Adding new axios documentation website link ([#3681](https://github.com/axios/axios/pull/3681), [#3707](https://github.com/axios/axios/pull/3707))
|
||||
- Updating documentation around dispatching requests ([#3772](https://github.com/axios/axios/pull/3772))
|
||||
- Adding documentation for the type guard isAxiosError ([#3767](https://github.com/axios/axios/pull/3767))
|
||||
- Adding explanation of cancel token ([#3803](https://github.com/axios/axios/pull/3803))
|
||||
- Updating CI status badge ([#3953](https://github.com/axios/axios/pull/3953))
|
||||
- Fixing errors with JSON documentation ([#3936](https://github.com/axios/axios/pull/3936))
|
||||
- Fixing README typo under Request Config ([#3825](https://github.com/axios/axios/pull/3825))
|
||||
- Adding axios-multi-api to the ecosystem file ([#3817](https://github.com/axios/axios/pull/3817))
|
||||
- Adding SECURITY.md to properly disclose security vulnerabilities ([#3981](https://github.com/axios/axios/pull/3981))
|
||||
|
||||
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)
|
||||
- [Sasha Korotkov](https://github.com/SashaKoro)
|
||||
- [Daniel Lopretto](https://github.com/timemachine3030)
|
||||
- [Mike Bishop](https://github.com/MikeBishop)
|
||||
- [Dmitriy Mozgovoy](https://github.com/DigitalBrainJS)
|
||||
- [Mark](https://github.com/bimbiltu)
|
||||
- [Philipe Gouveia Paixão](https://github.com/piiih)
|
||||
- [hippo](https://github.com/hippo2cat)
|
||||
- [ready-research](https://github.com/ready-research)
|
||||
- [Xianming Zhong](https://github.com/chinesedfan)
|
||||
- [Christopher Chrapka](https://github.com/OJezu)
|
||||
- [Brian Anglin](https://github.com/anglinb)
|
||||
- [Kohta Ito](https://github.com/koh110)
|
||||
- [Ali Clark](https://github.com/aliclark)
|
||||
- [caikan](https://github.com/caikan)
|
||||
- [Elina Gorshkova](https://github.com/elinagorshkova)
|
||||
- [Ryota Ikezawa](https://github.com/paveg)
|
||||
- [Nisar Hassan Naqvi](https://github.com/nisarhassan12)
|
||||
- [Jake](https://github.com/codemaster138)
|
||||
- [TagawaHirotaka](https://github.com/wafuwafu13)
|
||||
- [Johannes Jarbratt](https://github.com/johachi)
|
||||
- [Mo Sattler](https://github.com/MoSattler)
|
||||
- [Sam Carlton](https://github.com/ThatGuySam)
|
||||
- [Matt Czapliński](https://github.com/MattCCC)
|
||||
- [Ziding Zhang](https://github.com/zidingz)
|
||||
|
||||
### 0.21.1 (December 21, 2020)
|
||||
|
||||
Fixes and Functionality:
|
||||
|
||||
- Hotfix: Prevent SSRF (#3410)
|
||||
- Protocol not parsed when setting proxy config from env vars (#3070)
|
||||
- Updating axios in types to be lower case (#2797)
|
||||
- Adding a type guard for `AxiosError` (#2949)
|
||||
- Hotfix: Prevent SSRF ([#3410](https://github.com/axios/axios/pull/3410))
|
||||
- Protocol not parsed when setting proxy config from env vars ([#3070](https://github.com/axios/axios/pull/3070))
|
||||
- Updating axios in types to be lower case ([#2797](https://github.com/axios/axios/pull/2797))
|
||||
- Adding a type guard for `AxiosError` ([#2949](https://github.com/axios/axios/pull/2949))
|
||||
|
||||
Internal and Tests:
|
||||
|
||||
- Remove the skipping of the `socket` http test (#3364)
|
||||
- Use different socket for Win32 test (#3375)
|
||||
- Remove the skipping of the `socket` http test ([#3364](https://github.com/axios/axios/pull/3364))
|
||||
- Use different socket for Win32 test ([#3375](https://github.com/axios/axios/pull/3375))
|
||||
|
||||
Huge thanks to everyone who contributed to this release via code (authors listed below) or via reviews and triaging on GitHub:
|
||||
|
||||
|
||||
@@ -18,6 +18,7 @@ This is a list of axios related libraries and resources. If you have a suggestio
|
||||
* [r2curl](https://github.com/uyu423/r2curl) - Extracts the cURL command string from the Axios object. (AxiosResponse, AxiosRequestConfig)
|
||||
* [swagger-taxos-codegen](https://github.com/michalzaq12/swagger-taxos-codegen) - Axios based Swagger Codegen (tailored for typescript)
|
||||
* [axios-endpoints](https://github.com/renancaraujo/axios-endpoints) - Axios endpoints helps you to create a more concise endpoint mapping with axios.
|
||||
* [axios-multi-api](https://github.com/MattCCC/axios-multi-api) - Easy API handling whenever there are many endpoints to add. It helps to make Axios requests in an easy and declarative manner.
|
||||
|
||||
### Logging and debugging
|
||||
|
||||
@@ -36,5 +37,6 @@ This is a list of axios related libraries and resources. If you have a suggestio
|
||||
|
||||
* [axiosist](https://github.com/Gerhut/axiosist) - Axios based supertest: convert node.js request handler to axios adapter, used for node.js server unit test.
|
||||
* [axios-mock-adapter](https://github.com/ctimmerm/axios-mock-adapter) — Axios adapter that allows to easily mock requests
|
||||
* [axios-test-instance](https://github.com/remcohaszing/axios-test-instance) — Test NodeJS backends using Axios
|
||||
* [moxios](https://github.com/axios/moxios) - Mock axios requests for testing
|
||||
* [mocha-axios](https://github.com/jdrydn/mocha-axios) - Streamlined integration testing with Mocha & Axios
|
||||
|
||||
+21
-19
@@ -1,3 +1,4 @@
|
||||
// eslint-disable-next-line strict
|
||||
module.exports = function(grunt) {
|
||||
require('load-grunt-tasks')(grunt);
|
||||
|
||||
@@ -11,19 +12,6 @@ module.exports = function(grunt) {
|
||||
dist: 'dist/**'
|
||||
},
|
||||
|
||||
ts: {
|
||||
test: {
|
||||
options: {
|
||||
lib: [
|
||||
'es5',
|
||||
'es2015.promise',
|
||||
'dom'
|
||||
]
|
||||
},
|
||||
src: ['typings/index.d.ts', 'test/typescript/*.ts']
|
||||
}
|
||||
},
|
||||
|
||||
package2bower: {
|
||||
all: {
|
||||
fields: [
|
||||
@@ -37,6 +25,10 @@ module.exports = function(grunt) {
|
||||
}
|
||||
},
|
||||
|
||||
package2env: {
|
||||
all: {}
|
||||
},
|
||||
|
||||
usebanner: {
|
||||
all: {
|
||||
options: {
|
||||
@@ -70,8 +62,8 @@ module.exports = function(grunt) {
|
||||
src: ['test/unit/**/*.js']
|
||||
},
|
||||
options: {
|
||||
timeout: 30000,
|
||||
},
|
||||
timeout: 30000
|
||||
}
|
||||
},
|
||||
|
||||
watch: {
|
||||
@@ -88,12 +80,12 @@ module.exports = function(grunt) {
|
||||
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 bower = grunt.file.readJSON('bower.json');
|
||||
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];
|
||||
bower[field] = npm[field];
|
||||
}
|
||||
@@ -101,7 +93,17 @@ module.exports = function(grunt) {
|
||||
grunt.file.write('bower.json', JSON.stringify(bower, null, 2));
|
||||
});
|
||||
|
||||
grunt.registerTask('test', 'Run the jasmine and mocha tests', ['eslint', 'mochaTest', 'karma:single', 'ts']);
|
||||
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']);
|
||||
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']);
|
||||
};
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
|
||||
[](https://www.npmjs.org/package/axios)
|
||||
[](https://cdnjs.com/libraries/axios)
|
||||
[](https://travis-ci.org/axios/axios)
|
||||

|
||||
[](https://gitpod.io/#https://github.com/axios/axios)
|
||||
[](https://coveralls.io/r/mzabriskie/axios)
|
||||
[](https://packagephobia.now.sh/result?p=axios)
|
||||
@@ -32,6 +32,7 @@ Promise based HTTP client for the browser and node.js
|
||||
- [Custom instance defaults](#custom-instance-defaults)
|
||||
- [Config order of precedence](#config-order-of-precedence)
|
||||
- [Interceptors](#interceptors)
|
||||
- [Multiple Interceptors](#multiple-interceptors)
|
||||
- [Handling Errors](#handling-errors)
|
||||
- [Cancellation](#cancellation)
|
||||
- [Using application/x-www-form-urlencoded format](#using-applicationx-www-form-urlencoded-format)
|
||||
@@ -452,12 +453,36 @@ These are the available config options for making requests. Only the `url` is re
|
||||
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
|
||||
// automatically. If set to `true` will also remove the 'content-encoding' header
|
||||
// from the responses objects of all decompressed responses
|
||||
// - Node only (XHR cannot turn off decompression)
|
||||
decompress: true // default
|
||||
|
||||
// `insecureHTTPParser` boolean.
|
||||
// Indicates where to use an insecure HTTP parser that accepts invalid HTTP headers.
|
||||
// This may allow interoperability with non-conformant HTTP implementations.
|
||||
// Using the insecure parser should be avoided.
|
||||
// see options https://nodejs.org/dist/latest-v12.x/docs/api/http.html#http_http_request_url_options_callback
|
||||
// see also https://nodejs.org/en/blog/vulnerability/february-2020-security-releases/#strict-http-header-parsing-none
|
||||
insecureHTTPParser: undefined // default
|
||||
|
||||
// transitional options for backward compatibility that may be removed in the newer versions
|
||||
transitional: {
|
||||
// silent JSON parsing mode
|
||||
// `true` - ignore JSON parsing errors and set response.data to null if parsing failed (old behaviour)
|
||||
// `false` - throw SyntaxError if JSON parsing failed (Note: responseType must be set to 'json')
|
||||
silentJSONParsing: true, // default value for the current Axios version
|
||||
|
||||
// try to parse the response string as JSON even if `responseType` is not 'json'
|
||||
forcedJSONParsing: true,
|
||||
|
||||
// throw ETIMEDOUT error instead of generic ECONNABORTED on request timeouts
|
||||
clarifyTimeoutError: false,
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
@@ -621,6 +646,21 @@ axios.interceptors.request.use(function (config) {
|
||||
}, null, { runWhen: onGetCall });
|
||||
```
|
||||
|
||||
### Multiple Interceptors
|
||||
|
||||
Given you add multiple response interceptors
|
||||
and when the response was fulfilled
|
||||
- then each interceptor is executed
|
||||
- then they are executed in the order they were added
|
||||
- then only the last interceptor's result is returned
|
||||
- then every interceptor receives the result of it's predecessor
|
||||
- and when the fulfillment-interceptor throws
|
||||
- then the following fulfillment-interceptor is not called
|
||||
- then the following rejection-interceptor is called
|
||||
- once caught, another following fulfill-interceptor is called again (just like in a promise chain).
|
||||
|
||||
Read [the interceptor tests](./test/specs/interceptors.spec.js) for seeing all this in code.
|
||||
|
||||
## Handling Errors
|
||||
|
||||
```js
|
||||
@@ -713,7 +753,21 @@ axios.get('/user/12345', {
|
||||
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.
|
||||
|
||||
## Using application/x-www-form-urlencoded format
|
||||
|
||||
@@ -813,10 +867,21 @@ axios depends on a native ES6 Promise implementation to be [supported](http://ca
|
||||
If your environment doesn't support ES6 Promises, you can [polyfill](https://github.com/jakearchibald/es6-promise).
|
||||
|
||||
## TypeScript
|
||||
axios includes [TypeScript](http://typescriptlang.org) definitions.
|
||||
|
||||
axios includes [TypeScript](http://typescriptlang.org) definitions and a type guard for axios errors.
|
||||
|
||||
```typescript
|
||||
import axios from 'axios';
|
||||
axios.get('/user?ID=12345');
|
||||
let user: User = null;
|
||||
try {
|
||||
const { data } = await axios.get('/user?ID=12345');
|
||||
user = data.userDetails;
|
||||
} catch (error) {
|
||||
if (axios.isAxiosError(error)) {
|
||||
handleAxiosError(error);
|
||||
} else {
|
||||
handleUnexpectedError(error);
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
## Online one-click setup
|
||||
@@ -836,7 +901,7 @@ You can use Gitpod an online IDE(which is free for Open Source) for contributing
|
||||
|
||||
## Credits
|
||||
|
||||
axios is heavily inspired by the [$http service](https://docs.angularjs.org/api/ng/service/$http) provided in [Angular](https://angularjs.org/). Ultimately axios is an effort to provide a standalone `$http`-like service for use outside of Angular.
|
||||
axios is heavily inspired by the [$http service](https://docs.angularjs.org/api/ng/service/$http) provided in [AngularJS](https://angularjs.org/). Ultimately axios is an effort to provide a standalone `$http`-like service for use outside of AngularJS.
|
||||
|
||||
## License
|
||||
|
||||
|
||||
@@ -0,0 +1,5 @@
|
||||
# Security Policy
|
||||
|
||||
## Reporting a Vulnerability
|
||||
|
||||
Please report security issues to jasonsaayman@gmail.com
|
||||
@@ -1,5 +1,11 @@
|
||||
# Upgrade Guide
|
||||
|
||||
### 0.18.x -> 0.19.0
|
||||
|
||||
#### HTTPS Proxies
|
||||
|
||||
Routing through an https proxy now requires setting the `protocol` attribute of the proxy configuration to `https`
|
||||
|
||||
### 0.15.x -> 0.16.0
|
||||
|
||||
#### `Promise` Type Declarations
|
||||
|
||||
+2
-2
@@ -1,8 +1,8 @@
|
||||
{
|
||||
"name": "axios",
|
||||
"main": "./dist/axios.js",
|
||||
"version": "0.21.1",
|
||||
"homepage": "https://github.com/axios/axios",
|
||||
"version": "0.24.0",
|
||||
"homepage": "https://axios-http.com",
|
||||
"authors": [
|
||||
"Matt Zabriskie"
|
||||
],
|
||||
|
||||
Vendored
+2121
-1602
File diff suppressed because it is too large
Load Diff
Vendored
+1
-1
File diff suppressed because one or more lines are too long
Vendored
+1
-2
File diff suppressed because one or more lines are too long
Vendored
+1
-1
File diff suppressed because one or more lines are too long
Vendored
+77
-32
@@ -1,9 +1,21 @@
|
||||
export interface AxiosTransformer {
|
||||
(data: any, headers?: any): any;
|
||||
// TypeScript Version: 3.0
|
||||
|
||||
export type AxiosRequestHeaders = Record<string, string | number | boolean>;
|
||||
|
||||
export type AxiosResponseHeaders = Record<string, string> & {
|
||||
"set-cookie"?: string[]
|
||||
};
|
||||
|
||||
export interface AxiosRequestTransformer {
|
||||
(data: any, headers?: AxiosRequestHeaders): any;
|
||||
}
|
||||
|
||||
export interface AxiosResponseTransformer {
|
||||
(data: any, headers?: AxiosResponseHeaders): any;
|
||||
}
|
||||
|
||||
export interface AxiosAdapter {
|
||||
(config: AxiosRequestConfig): AxiosPromise<any>;
|
||||
(config: AxiosRequestConfig): AxiosPromise;
|
||||
}
|
||||
|
||||
export interface AxiosBasicCredentials {
|
||||
@@ -16,7 +28,7 @@ export interface AxiosProxyConfig {
|
||||
port: number;
|
||||
auth?: {
|
||||
username: string;
|
||||
password:string;
|
||||
password: string;
|
||||
};
|
||||
protocol?: string;
|
||||
}
|
||||
@@ -31,7 +43,7 @@ export type Method =
|
||||
| 'patch' | 'PATCH'
|
||||
| 'purge' | 'PURGE'
|
||||
| 'link' | 'LINK'
|
||||
| 'unlink' | 'UNLINK'
|
||||
| 'unlink' | 'UNLINK';
|
||||
|
||||
export type ResponseType =
|
||||
| 'arraybuffer'
|
||||
@@ -39,18 +51,24 @@ export type ResponseType =
|
||||
| 'document'
|
||||
| 'json'
|
||||
| 'text'
|
||||
| 'stream'
|
||||
| 'stream';
|
||||
|
||||
export interface AxiosRequestConfig {
|
||||
export interface TransitionalOptions {
|
||||
silentJSONParsing?: boolean;
|
||||
forcedJSONParsing?: boolean;
|
||||
clarifyTimeoutError?: boolean;
|
||||
}
|
||||
|
||||
export interface AxiosRequestConfig<D = any> {
|
||||
url?: string;
|
||||
method?: Method;
|
||||
baseURL?: string;
|
||||
transformRequest?: AxiosTransformer | AxiosTransformer[];
|
||||
transformResponse?: AxiosTransformer | AxiosTransformer[];
|
||||
headers?: any;
|
||||
transformRequest?: AxiosRequestTransformer | AxiosRequestTransformer[];
|
||||
transformResponse?: AxiosResponseTransformer | AxiosResponseTransformer[];
|
||||
headers?: AxiosRequestHeaders;
|
||||
params?: any;
|
||||
paramsSerializer?: (params: any) => string;
|
||||
data?: any;
|
||||
data?: D;
|
||||
timeout?: number;
|
||||
timeoutErrorMessage?: string;
|
||||
withCredentials?: boolean;
|
||||
@@ -71,22 +89,43 @@ export interface AxiosRequestConfig {
|
||||
proxy?: AxiosProxyConfig | false;
|
||||
cancelToken?: CancelToken;
|
||||
decompress?: boolean;
|
||||
transitional?: TransitionalOptions;
|
||||
signal?: AbortSignal;
|
||||
insecureHTTPParser?: boolean;
|
||||
}
|
||||
|
||||
export interface AxiosResponse<T = any> {
|
||||
export interface HeadersDefaults {
|
||||
common: AxiosRequestHeaders;
|
||||
delete: AxiosRequestHeaders;
|
||||
get: AxiosRequestHeaders;
|
||||
head: AxiosRequestHeaders;
|
||||
post: AxiosRequestHeaders;
|
||||
put: AxiosRequestHeaders;
|
||||
patch: AxiosRequestHeaders;
|
||||
options?: AxiosRequestHeaders;
|
||||
purge?: AxiosRequestHeaders;
|
||||
link?: AxiosRequestHeaders;
|
||||
unlink?: AxiosRequestHeaders;
|
||||
}
|
||||
|
||||
export interface AxiosDefaults<D = any> extends Omit<AxiosRequestConfig<D>, 'headers'> {
|
||||
headers: HeadersDefaults;
|
||||
}
|
||||
|
||||
export interface AxiosResponse<T = any, D = any> {
|
||||
data: T;
|
||||
status: number;
|
||||
statusText: string;
|
||||
headers: any;
|
||||
config: AxiosRequestConfig;
|
||||
headers: AxiosResponseHeaders;
|
||||
config: AxiosRequestConfig<D>;
|
||||
request?: any;
|
||||
}
|
||||
|
||||
export interface AxiosError<T = any> extends Error {
|
||||
config: AxiosRequestConfig;
|
||||
export interface AxiosError<T = any, D = any> extends Error {
|
||||
config: AxiosRequestConfig<D>;
|
||||
code?: string;
|
||||
request?: any;
|
||||
response?: AxiosResponse<T>;
|
||||
response?: AxiosResponse<T, D>;
|
||||
isAxiosError: boolean;
|
||||
toJSON: () => object;
|
||||
}
|
||||
@@ -99,7 +138,7 @@ export interface CancelStatic {
|
||||
}
|
||||
|
||||
export interface Cancel {
|
||||
message: string;
|
||||
message: string | undefined;
|
||||
}
|
||||
|
||||
export interface Canceler {
|
||||
@@ -123,35 +162,41 @@ export interface CancelTokenSource {
|
||||
}
|
||||
|
||||
export interface AxiosInterceptorManager<V> {
|
||||
use(onFulfilled?: (value: V) => V | Promise<V>, onRejected?: (error: any) => any): number;
|
||||
use<T = V>(onFulfilled?: (value: V) => T | Promise<T>, onRejected?: (error: any) => any): number;
|
||||
eject(id: number): void;
|
||||
}
|
||||
|
||||
export interface AxiosInstance {
|
||||
(config: AxiosRequestConfig): AxiosPromise;
|
||||
(url: string, config?: AxiosRequestConfig): AxiosPromise;
|
||||
defaults: AxiosRequestConfig;
|
||||
export class Axios {
|
||||
constructor(config?: AxiosRequestConfig);
|
||||
defaults: AxiosDefaults;
|
||||
interceptors: {
|
||||
request: AxiosInterceptorManager<AxiosRequestConfig>;
|
||||
response: AxiosInterceptorManager<AxiosResponse>;
|
||||
};
|
||||
getUri(config?: AxiosRequestConfig): string;
|
||||
request<T = any, R = AxiosResponse<T>> (config: AxiosRequestConfig): Promise<R>;
|
||||
get<T = any, R = AxiosResponse<T>>(url: string, config?: AxiosRequestConfig): Promise<R>;
|
||||
delete<T = any, R = AxiosResponse<T>>(url: string, config?: AxiosRequestConfig): Promise<R>;
|
||||
head<T = any, R = AxiosResponse<T>>(url: string, config?: AxiosRequestConfig): Promise<R>;
|
||||
options<T = any, R = AxiosResponse<T>>(url: string, config?: AxiosRequestConfig): Promise<R>;
|
||||
post<T = any, R = AxiosResponse<T>>(url: string, data?: any, config?: AxiosRequestConfig): Promise<R>;
|
||||
put<T = any, R = AxiosResponse<T>>(url: string, data?: any, config?: AxiosRequestConfig): Promise<R>;
|
||||
patch<T = any, R = AxiosResponse<T>>(url: string, data?: any, config?: AxiosRequestConfig): Promise<R>;
|
||||
request<T = any, R = AxiosResponse<T>, D = any>(config: AxiosRequestConfig<D>): Promise<R>;
|
||||
get<T = any, R = AxiosResponse<T>, D = any>(url: string, config?: AxiosRequestConfig<D>): Promise<R>;
|
||||
delete<T = any, R = AxiosResponse<T>, D = any>(url: string, config?: AxiosRequestConfig<D>): Promise<R>;
|
||||
head<T = any, R = AxiosResponse<T>, D = any>(url: string, config?: AxiosRequestConfig<D>): Promise<R>;
|
||||
options<T = any, R = AxiosResponse<T>, D = any>(url: string, config?: AxiosRequestConfig<D>): Promise<R>;
|
||||
post<T = any, R = AxiosResponse<T>, D = any>(url: string, data?: D, config?: AxiosRequestConfig<D>): Promise<R>;
|
||||
put<T = any, R = AxiosResponse<T>, D = any>(url: string, data?: D, config?: AxiosRequestConfig<D>): Promise<R>;
|
||||
patch<T = any, R = AxiosResponse<T>, D = any>(url: string, data?: D, config?: AxiosRequestConfig<D>): Promise<R>;
|
||||
}
|
||||
|
||||
export interface AxiosInstance extends Axios {
|
||||
(config: AxiosRequestConfig): AxiosPromise;
|
||||
(url: string, config?: AxiosRequestConfig): AxiosPromise;
|
||||
}
|
||||
|
||||
export interface AxiosStatic extends AxiosInstance {
|
||||
create(config?: AxiosRequestConfig): AxiosInstance;
|
||||
Cancel: CancelStatic;
|
||||
CancelToken: CancelTokenStatic;
|
||||
Axios: typeof Axios;
|
||||
readonly VERSION: string;
|
||||
isCancel(value: any): boolean;
|
||||
all<T>(values: (T | Promise<T>)[]): Promise<T[]>;
|
||||
all<T>(values: Array<T | Promise<T>>): Promise<T[]>;
|
||||
spread<T, R>(callback: (...args: T[]) => R): (array: T[]) => R;
|
||||
isAxiosError(payload: any): payload is AxiosError;
|
||||
}
|
||||
|
||||
@@ -127,6 +127,9 @@ module.exports = function(config) {
|
||||
'Running on Travis.'
|
||||
);
|
||||
browsers = ['Firefox'];
|
||||
} else if (process.env.GITHUB_ACTIONS !== 'false') {
|
||||
console.log('Running ci on Github Actions.');
|
||||
browsers = ['FirefoxHeadless', 'ChromeHeadless'];
|
||||
} else {
|
||||
console.log('Running locally since SAUCE_USERNAME and SAUCE_ACCESS_KEY environment variables are not set.');
|
||||
browsers = ['Firefox', 'Chrome'];
|
||||
|
||||
+92
-17
@@ -10,9 +10,11 @@ var httpFollow = require('follow-redirects').http;
|
||||
var httpsFollow = require('follow-redirects').https;
|
||||
var url = require('url');
|
||||
var zlib = require('zlib');
|
||||
var pkg = require('./../../package.json');
|
||||
var VERSION = require('./../env/data').version;
|
||||
var createError = require('../core/createError');
|
||||
var enhanceError = require('../core/enhanceError');
|
||||
var defaults = require('../defaults');
|
||||
var Cancel = require('../cancel/Cancel');
|
||||
|
||||
var isHttps = /https:?/;
|
||||
|
||||
@@ -44,27 +46,45 @@ function setProxy(options, proxy, location) {
|
||||
/*eslint consistent-return:0*/
|
||||
module.exports = function httpAdapter(config) {
|
||||
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) {
|
||||
done();
|
||||
resolvePromise(value);
|
||||
};
|
||||
var rejected = false;
|
||||
var reject = function reject(value) {
|
||||
done();
|
||||
rejected = true;
|
||||
rejectPromise(value);
|
||||
};
|
||||
var data = config.data;
|
||||
var headers = config.headers;
|
||||
var headerNames = {};
|
||||
|
||||
Object.keys(headers).forEach(function storeLowerName(name) {
|
||||
headerNames[name.toLowerCase()] = name;
|
||||
});
|
||||
|
||||
// Set User-Agent (required by some servers)
|
||||
// See https://github.com/axios/axios/issues/69
|
||||
if ('User-Agent' in headers || 'user-agent' in headers) {
|
||||
if ('user-agent' in headerNames) {
|
||||
// User-Agent is specified; handle case where no UA header is desired
|
||||
if (!headers['User-Agent'] && !headers['user-agent']) {
|
||||
delete headers['User-Agent'];
|
||||
delete headers['user-agent'];
|
||||
if (!headers[headerNames['user-agent']]) {
|
||||
delete headers[headerNames['user-agent']];
|
||||
}
|
||||
// Otherwise, use specified value
|
||||
} else {
|
||||
// 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)) {
|
||||
@@ -81,8 +101,14 @@ module.exports = function httpAdapter(config) {
|
||||
));
|
||||
}
|
||||
|
||||
if (config.maxBodyLength > -1 && data.length > config.maxBodyLength) {
|
||||
return reject(createError('Request body larger than maxBodyLength limit', config));
|
||||
}
|
||||
|
||||
// Add Content-Length header if data exists
|
||||
headers['Content-Length'] = data.length;
|
||||
if (!headerNames['content-length']) {
|
||||
headers['Content-Length'] = data.length;
|
||||
}
|
||||
}
|
||||
|
||||
// HTTP basic authentication
|
||||
@@ -105,8 +131,8 @@ module.exports = function httpAdapter(config) {
|
||||
auth = urlUsername + ':' + urlPassword;
|
||||
}
|
||||
|
||||
if (auth) {
|
||||
delete headers.Authorization;
|
||||
if (auth && headerNames.authorization) {
|
||||
delete headers[headerNames.authorization];
|
||||
}
|
||||
|
||||
var isHttpsRequest = isHttps.test(protocol);
|
||||
@@ -198,6 +224,10 @@ module.exports = function httpAdapter(config) {
|
||||
options.maxBodyLength = config.maxBodyLength;
|
||||
}
|
||||
|
||||
if (config.insecureHTTPParser) {
|
||||
options.insecureHTTPParser = config.insecureHTTPParser;
|
||||
}
|
||||
|
||||
// Create the request
|
||||
var req = transport.request(options, function handleResponse(res) {
|
||||
if (req.aborted) return;
|
||||
@@ -238,24 +268,36 @@ module.exports = function httpAdapter(config) {
|
||||
settle(resolve, reject, response);
|
||||
} else {
|
||||
var responseBuffer = [];
|
||||
var totalResponseBytes = 0;
|
||||
stream.on('data', function handleStreamData(chunk) {
|
||||
responseBuffer.push(chunk);
|
||||
totalResponseBytes += chunk.length;
|
||||
|
||||
// make sure the content length is not over the maxContentLength if specified
|
||||
if (config.maxContentLength > -1 && Buffer.concat(responseBuffer).length > config.maxContentLength) {
|
||||
if (config.maxContentLength > -1 && totalResponseBytes > config.maxContentLength) {
|
||||
// stream.destoy() emit aborted event before calling reject() on Node.js v16
|
||||
rejected = true;
|
||||
stream.destroy();
|
||||
reject(createError('maxContentLength size of ' + config.maxContentLength + ' exceeded',
|
||||
config, null, lastRequest));
|
||||
}
|
||||
});
|
||||
|
||||
stream.on('aborted', function handlerStreamAborted() {
|
||||
if (rejected) {
|
||||
return;
|
||||
}
|
||||
stream.destroy();
|
||||
reject(createError('error request aborted', config, 'ERR_REQUEST_ABORTED', lastRequest));
|
||||
});
|
||||
|
||||
stream.on('error', function handleStreamError(err) {
|
||||
if (req.aborted) return;
|
||||
reject(enhanceError(err, config, null, lastRequest));
|
||||
});
|
||||
|
||||
stream.on('end', function handleStreamEnd() {
|
||||
var responseData = Buffer.concat(responseBuffer);
|
||||
var responseData = responseBuffer.length === 1 ? responseBuffer[0] : Buffer.concat(responseBuffer);
|
||||
if (config.responseType !== 'arraybuffer') {
|
||||
responseData = responseData.toString(config.responseEncoding);
|
||||
if (!config.responseEncoding || config.responseEncoding === 'utf8') {
|
||||
@@ -275,29 +317,62 @@ module.exports = function httpAdapter(config) {
|
||||
reject(enhanceError(err, config, null, req));
|
||||
});
|
||||
|
||||
// set tcp keep alive to prevent drop connection by peer
|
||||
req.on('socket', function handleRequestSocket(socket) {
|
||||
// default interval of sending ack packet is 1 minute
|
||||
socket.setKeepAlive(true, 1000 * 60);
|
||||
});
|
||||
|
||||
// Handle request timeout
|
||||
if (config.timeout) {
|
||||
// This is forcing a int timeout to avoid problems if the `req` interface doesn't handle other types.
|
||||
var timeout = parseInt(config.timeout, 10);
|
||||
|
||||
if (isNaN(timeout)) {
|
||||
reject(createError(
|
||||
'error trying to parse `config.timeout` to int',
|
||||
config,
|
||||
'ERR_PARSE_TIMEOUT',
|
||||
req
|
||||
));
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
// Sometime, the response will be very slow, and does not respond, the connect event will be block by event loop system.
|
||||
// And timer callback will be fired, and abort() will be invoked before connection, then get "socket hang up" and code ECONNRESET.
|
||||
// At this time, if we have a large number of request, nodejs will hang up some socket on background. and the number will up and up.
|
||||
// And then these socket which be hang up will devoring CPU little by little.
|
||||
// ClientRequest.setTimeout will be fired on the specify milliseconds, and can make sure that abort() will be fired after connect.
|
||||
req.setTimeout(config.timeout, function handleRequestTimeout() {
|
||||
req.setTimeout(timeout, function handleRequestTimeout() {
|
||||
req.abort();
|
||||
reject(createError('timeout of ' + config.timeout + 'ms exceeded', config, 'ECONNABORTED', req));
|
||||
var transitional = config.transitional || defaults.transitional;
|
||||
reject(createError(
|
||||
'timeout of ' + timeout + 'ms exceeded',
|
||||
config,
|
||||
transitional.clarifyTimeoutError ? 'ETIMEDOUT' : 'ECONNABORTED',
|
||||
req
|
||||
));
|
||||
});
|
||||
}
|
||||
|
||||
if (config.cancelToken) {
|
||||
if (config.cancelToken || config.signal) {
|
||||
// Handle cancellation
|
||||
config.cancelToken.promise.then(function onCanceled(cancel) {
|
||||
// eslint-disable-next-line func-names
|
||||
onCanceled = function(cancel) {
|
||||
if (req.aborted) return;
|
||||
|
||||
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
|
||||
if (utils.isStream(data)) {
|
||||
data.on('error', function handleStreamError(err) {
|
||||
|
||||
+66
-33
@@ -8,11 +8,24 @@ var buildFullPath = require('../core/buildFullPath');
|
||||
var parseHeaders = require('./../helpers/parseHeaders');
|
||||
var isURLSameOrigin = require('./../helpers/isURLSameOrigin');
|
||||
var createError = require('../core/createError');
|
||||
var defaults = require('../defaults');
|
||||
var Cancel = require('../cancel/Cancel');
|
||||
|
||||
module.exports = function xhrAdapter(config) {
|
||||
return new Promise(function dispatchXhrRequest(resolve, reject) {
|
||||
var requestData = config.data;
|
||||
var requestHeaders = config.headers;
|
||||
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)) {
|
||||
delete requestHeaders['Content-Type']; // Let the browser set it
|
||||
@@ -33,23 +46,14 @@ module.exports = function xhrAdapter(config) {
|
||||
// Set the request timeout in MS
|
||||
request.timeout = config.timeout;
|
||||
|
||||
// Listen for ready state
|
||||
request.onreadystatechange = function handleLoad() {
|
||||
if (!request || request.readyState !== 4) {
|
||||
function onloadend() {
|
||||
if (!request) {
|
||||
return;
|
||||
}
|
||||
|
||||
// The request errored out and we didn't get a response, this will be
|
||||
// handled by onerror instead
|
||||
// With one exception: request that using file: protocol, most browsers
|
||||
// will return status as 0 even though it's a successful request
|
||||
if (request.status === 0 && !(request.responseURL && request.responseURL.indexOf('file:') === 0)) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Prepare the response
|
||||
var responseHeaders = 'getAllResponseHeaders' in request ? parseHeaders(request.getAllResponseHeaders()) : null;
|
||||
var responseData = !config.responseType || config.responseType === 'text' ? request.responseText : request.response;
|
||||
var responseData = !responseType || responseType === 'text' || responseType === 'json' ?
|
||||
request.responseText : request.response;
|
||||
var response = {
|
||||
data: responseData,
|
||||
status: request.status,
|
||||
@@ -59,11 +63,40 @@ module.exports = function xhrAdapter(config) {
|
||||
request: request
|
||||
};
|
||||
|
||||
settle(resolve, reject, response);
|
||||
settle(function _resolve(value) {
|
||||
resolve(value);
|
||||
done();
|
||||
}, function _reject(err) {
|
||||
reject(err);
|
||||
done();
|
||||
}, response);
|
||||
|
||||
// Clean up request
|
||||
request = null;
|
||||
};
|
||||
}
|
||||
|
||||
if ('onloadend' in request) {
|
||||
// Use onloadend if available
|
||||
request.onloadend = onloadend;
|
||||
} else {
|
||||
// Listen for ready state to emulate onloadend
|
||||
request.onreadystatechange = function handleLoad() {
|
||||
if (!request || request.readyState !== 4) {
|
||||
return;
|
||||
}
|
||||
|
||||
// The request errored out and we didn't get a response, this will be
|
||||
// handled by onerror instead
|
||||
// With one exception: request that using file: protocol, most browsers
|
||||
// will return status as 0 even though it's a successful request
|
||||
if (request.status === 0 && !(request.responseURL && request.responseURL.indexOf('file:') === 0)) {
|
||||
return;
|
||||
}
|
||||
// readystate handler is calling before onerror or ontimeout handlers,
|
||||
// so we should call onloadend on the next 'tick'
|
||||
setTimeout(onloadend);
|
||||
};
|
||||
}
|
||||
|
||||
// Handle browser request cancellation (as opposed to a manual cancellation)
|
||||
request.onabort = function handleAbort() {
|
||||
@@ -89,11 +122,15 @@ module.exports = function xhrAdapter(config) {
|
||||
|
||||
// Handle timeout
|
||||
request.ontimeout = function handleTimeout() {
|
||||
var timeoutErrorMessage = 'timeout of ' + config.timeout + 'ms exceeded';
|
||||
var timeoutErrorMessage = config.timeout ? 'timeout of ' + config.timeout + 'ms exceeded' : 'timeout exceeded';
|
||||
var transitional = config.transitional || defaults.transitional;
|
||||
if (config.timeoutErrorMessage) {
|
||||
timeoutErrorMessage = config.timeoutErrorMessage;
|
||||
}
|
||||
reject(createError(timeoutErrorMessage, config, 'ECONNABORTED',
|
||||
reject(createError(
|
||||
timeoutErrorMessage,
|
||||
config,
|
||||
transitional.clarifyTimeoutError ? 'ETIMEDOUT' : 'ECONNABORTED',
|
||||
request));
|
||||
|
||||
// Clean up request
|
||||
@@ -133,16 +170,8 @@ module.exports = function xhrAdapter(config) {
|
||||
}
|
||||
|
||||
// Add responseType to request if needed
|
||||
if (config.responseType) {
|
||||
try {
|
||||
request.responseType = config.responseType;
|
||||
} catch (e) {
|
||||
// Expected DOMException thrown by browsers not compatible XMLHttpRequest Level 2.
|
||||
// But, this can be suppressed for 'json' type as it can be parsed by default 'transformResponse' function.
|
||||
if (config.responseType !== 'json') {
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
if (responseType && responseType !== 'json') {
|
||||
request.responseType = config.responseType;
|
||||
}
|
||||
|
||||
// Handle progress if needed
|
||||
@@ -155,18 +184,22 @@ module.exports = function xhrAdapter(config) {
|
||||
request.upload.addEventListener('progress', config.onUploadProgress);
|
||||
}
|
||||
|
||||
if (config.cancelToken) {
|
||||
if (config.cancelToken || config.signal) {
|
||||
// Handle cancellation
|
||||
config.cancelToken.promise.then(function onCanceled(cancel) {
|
||||
// eslint-disable-next-line func-names
|
||||
onCanceled = function(cancel) {
|
||||
if (!request) {
|
||||
return;
|
||||
}
|
||||
|
||||
reject(!cancel || (cancel && cancel.type) ? new Cancel('canceled') : cancel);
|
||||
request.abort();
|
||||
reject(cancel);
|
||||
// Clean up request
|
||||
request = null;
|
||||
});
|
||||
};
|
||||
|
||||
config.cancelToken && config.cancelToken.subscribe(onCanceled);
|
||||
if (config.signal) {
|
||||
config.signal.aborted ? onCanceled() : config.signal.addEventListener('abort', onCanceled);
|
||||
}
|
||||
}
|
||||
|
||||
if (!requestData) {
|
||||
|
||||
+6
-5
@@ -22,6 +22,11 @@ function createInstance(defaultConfig) {
|
||||
// Copy context to instance
|
||||
utils.extend(instance, context);
|
||||
|
||||
// Factory for creating new instances
|
||||
instance.create = function create(instanceConfig) {
|
||||
return createInstance(mergeConfig(defaultConfig, instanceConfig));
|
||||
};
|
||||
|
||||
return instance;
|
||||
}
|
||||
|
||||
@@ -31,15 +36,11 @@ var axios = createInstance(defaults);
|
||||
// Expose Axios class to allow class inheritance
|
||||
axios.Axios = Axios;
|
||||
|
||||
// Factory for creating new instances
|
||||
axios.create = function create(instanceConfig) {
|
||||
return createInstance(mergeConfig(axios.defaults, instanceConfig));
|
||||
};
|
||||
|
||||
// Expose Cancel & CancelToken
|
||||
axios.Cancel = require('./cancel/Cancel');
|
||||
axios.CancelToken = require('./cancel/CancelToken');
|
||||
axios.isCancel = require('./cancel/isCancel');
|
||||
axios.VERSION = require('./env/data').version;
|
||||
|
||||
// Expose all/spread
|
||||
axios.all = function all(promises) {
|
||||
|
||||
@@ -14,11 +14,42 @@ function CancelToken(executor) {
|
||||
}
|
||||
|
||||
var resolvePromise;
|
||||
|
||||
this.promise = new Promise(function promiseExecutor(resolve) {
|
||||
resolvePromise = resolve;
|
||||
});
|
||||
|
||||
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) {
|
||||
if (token.reason) {
|
||||
// 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,
|
||||
* cancels the `CancelToken`.
|
||||
|
||||
+18
-6
@@ -5,7 +5,9 @@ var buildURL = require('../helpers/buildURL');
|
||||
var InterceptorManager = require('./InterceptorManager');
|
||||
var dispatchRequest = require('./dispatchRequest');
|
||||
var mergeConfig = require('./mergeConfig');
|
||||
var validator = require('../helpers/validator');
|
||||
|
||||
var validators = validator.validators;
|
||||
/**
|
||||
* Create a new instance of Axios
|
||||
*
|
||||
@@ -24,14 +26,14 @@ function Axios(instanceConfig) {
|
||||
*
|
||||
* @param {Object} config The config specific for this request (merged with this.defaults)
|
||||
*/
|
||||
Axios.prototype.request = function request(config) {
|
||||
Axios.prototype.request = function request(configOrUrl, config) {
|
||||
/*eslint no-param-reassign:0*/
|
||||
// Allow for axios('example/url'[, config]) a la fetch API
|
||||
if (typeof config === 'string') {
|
||||
config = arguments[1] || {};
|
||||
config.url = arguments[0];
|
||||
} else {
|
||||
if (typeof configOrUrl === 'string') {
|
||||
config = config || {};
|
||||
config.url = configOrUrl;
|
||||
} else {
|
||||
config = configOrUrl || {};
|
||||
}
|
||||
|
||||
config = mergeConfig(this.defaults, config);
|
||||
@@ -45,6 +47,16 @@ Axios.prototype.request = function request(config) {
|
||||
config.method = 'get';
|
||||
}
|
||||
|
||||
var transitional = config.transitional;
|
||||
|
||||
if (transitional !== undefined) {
|
||||
validator.assertOptions(transitional, {
|
||||
silentJSONParsing: validators.transitional(validators.boolean),
|
||||
forcedJSONParsing: validators.transitional(validators.boolean),
|
||||
clarifyTimeoutError: validators.transitional(validators.boolean)
|
||||
}, false);
|
||||
}
|
||||
|
||||
// filter out skipped interceptors
|
||||
var requestInterceptorChain = [];
|
||||
var synchronousRequestInterceptors = true;
|
||||
@@ -69,7 +81,7 @@ Axios.prototype.request = function request(config) {
|
||||
var chain = [dispatchRequest, undefined];
|
||||
|
||||
Array.prototype.unshift.apply(chain, requestInterceptorChain);
|
||||
chain.concat(responseInterceptorChain);
|
||||
chain = chain.concat(responseInterceptorChain);
|
||||
|
||||
promise = Promise.resolve(config);
|
||||
while (chain.length) {
|
||||
|
||||
@@ -3,5 +3,6 @@
|
||||
The modules found in `core/` should be modules that are specific to the domain logic of axios. These modules would most likely not make sense to be consumed outside of the axios module, as their logic is too specific. Some examples of core modules are:
|
||||
|
||||
- Dispatching requests
|
||||
- Requests sent via `adapters/` (see lib/adapters/README.md)
|
||||
- Managing interceptors
|
||||
- Handling config
|
||||
|
||||
@@ -4,6 +4,7 @@ var utils = require('./../utils');
|
||||
var transformData = require('./transformData');
|
||||
var isCancel = require('../cancel/isCancel');
|
||||
var defaults = require('../defaults');
|
||||
var Cancel = require('../cancel/Cancel');
|
||||
|
||||
/**
|
||||
* Throws a `Cancel` if cancellation has been requested.
|
||||
@@ -12,6 +13,10 @@ function throwIfCancellationRequested(config) {
|
||||
if (config.cancelToken) {
|
||||
config.cancelToken.throwIfRequested();
|
||||
}
|
||||
|
||||
if (config.signal && config.signal.aborted) {
|
||||
throw new Cancel('canceled');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -27,7 +32,8 @@ module.exports = function dispatchRequest(config) {
|
||||
config.headers = config.headers || {};
|
||||
|
||||
// Transform request data
|
||||
config.data = transformData(
|
||||
config.data = transformData.call(
|
||||
config,
|
||||
config.data,
|
||||
config.headers,
|
||||
config.transformRequest
|
||||
@@ -53,7 +59,8 @@ module.exports = function dispatchRequest(config) {
|
||||
throwIfCancellationRequested(config);
|
||||
|
||||
// Transform response data
|
||||
response.data = transformData(
|
||||
response.data = transformData.call(
|
||||
config,
|
||||
response.data,
|
||||
response.headers,
|
||||
config.transformResponse
|
||||
@@ -66,7 +73,8 @@ module.exports = function dispatchRequest(config) {
|
||||
|
||||
// Transform response data
|
||||
if (reason && reason.response) {
|
||||
reason.response.data = transformData(
|
||||
reason.response.data = transformData.call(
|
||||
config,
|
||||
reason.response.data,
|
||||
reason.response.headers,
|
||||
config.transformResponse
|
||||
|
||||
@@ -35,7 +35,8 @@ module.exports = function enhanceError(error, config, code, request, response) {
|
||||
stack: this.stack,
|
||||
// Axios
|
||||
config: this.config,
|
||||
code: this.code
|
||||
code: this.code,
|
||||
status: this.response && this.response.status ? this.response.status : null
|
||||
};
|
||||
};
|
||||
return error;
|
||||
|
||||
+51
-39
@@ -15,17 +15,6 @@ module.exports = function mergeConfig(config1, config2) {
|
||||
config2 = config2 || {};
|
||||
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) {
|
||||
if (utils.isPlainObject(target) && utils.isPlainObject(source)) {
|
||||
return utils.merge(target, source);
|
||||
@@ -37,51 +26,74 @@ module.exports = function mergeConfig(config1, config2) {
|
||||
return source;
|
||||
}
|
||||
|
||||
// eslint-disable-next-line consistent-return
|
||||
function mergeDeepProperties(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])) {
|
||||
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])) {
|
||||
config[prop] = getMergedValue(undefined, config2[prop]);
|
||||
return getMergedValue(undefined, config2[prop]);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
utils.forEach(mergeDeepPropertiesKeys, mergeDeepProperties);
|
||||
|
||||
utils.forEach(defaultToConfig2Keys, function defaultToConfig2(prop) {
|
||||
// eslint-disable-next-line consistent-return
|
||||
function defaultToConfig2(prop) {
|
||||
if (!utils.isUndefined(config2[prop])) {
|
||||
config[prop] = getMergedValue(undefined, config2[prop]);
|
||||
return getMergedValue(undefined, config2[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) {
|
||||
config[prop] = getMergedValue(config1[prop], config2[prop]);
|
||||
return getMergedValue(config1[prop], config2[prop]);
|
||||
} 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;
|
||||
};
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
'use strict';
|
||||
|
||||
var utils = require('./../utils');
|
||||
var defaults = require('./../defaults');
|
||||
|
||||
/**
|
||||
* Transform the data for a request or a response
|
||||
@@ -11,9 +12,10 @@ var utils = require('./../utils');
|
||||
* @returns {*} The resulting transformed data
|
||||
*/
|
||||
module.exports = function transformData(data, headers, fns) {
|
||||
var context = this || defaults;
|
||||
/*eslint no-param-reassign:0*/
|
||||
utils.forEach(fns, function transform(fn) {
|
||||
data = fn(data, headers);
|
||||
data = fn.call(context, data, headers);
|
||||
});
|
||||
|
||||
return data;
|
||||
|
||||
+49
-13
@@ -2,6 +2,7 @@
|
||||
|
||||
var utils = require('./utils');
|
||||
var normalizeHeaderName = require('./helpers/normalizeHeaderName');
|
||||
var enhanceError = require('./core/enhanceError');
|
||||
|
||||
var DEFAULT_CONTENT_TYPE = {
|
||||
'Content-Type': 'application/x-www-form-urlencoded'
|
||||
@@ -25,12 +26,35 @@ function getDefaultAdapter() {
|
||||
return adapter;
|
||||
}
|
||||
|
||||
function stringifySafely(rawValue, parser, encoder) {
|
||||
if (utils.isString(rawValue)) {
|
||||
try {
|
||||
(parser || JSON.parse)(rawValue);
|
||||
return utils.trim(rawValue);
|
||||
} catch (e) {
|
||||
if (e.name !== 'SyntaxError') {
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return (encoder || JSON.stringify)(rawValue);
|
||||
}
|
||||
|
||||
var defaults = {
|
||||
|
||||
transitional: {
|
||||
silentJSONParsing: true,
|
||||
forcedJSONParsing: true,
|
||||
clarifyTimeoutError: false
|
||||
},
|
||||
|
||||
adapter: getDefaultAdapter(),
|
||||
|
||||
transformRequest: [function transformRequest(data, headers) {
|
||||
normalizeHeaderName(headers, 'Accept');
|
||||
normalizeHeaderName(headers, 'Content-Type');
|
||||
|
||||
if (utils.isFormData(data) ||
|
||||
utils.isArrayBuffer(data) ||
|
||||
utils.isBuffer(data) ||
|
||||
@@ -47,21 +71,33 @@ var defaults = {
|
||||
setContentTypeIfUnset(headers, 'application/x-www-form-urlencoded;charset=utf-8');
|
||||
return data.toString();
|
||||
}
|
||||
if (utils.isObject(data)) {
|
||||
setContentTypeIfUnset(headers, 'application/json;charset=utf-8');
|
||||
return JSON.stringify(data);
|
||||
if (utils.isObject(data) || (headers && headers['Content-Type'] === 'application/json')) {
|
||||
setContentTypeIfUnset(headers, 'application/json');
|
||||
return stringifySafely(data);
|
||||
}
|
||||
return data;
|
||||
}],
|
||||
|
||||
transformResponse: [function transformResponse(data) {
|
||||
var result = data;
|
||||
if (utils.isString(result) && result.length) {
|
||||
var transitional = this.transitional || defaults.transitional;
|
||||
var silentJSONParsing = transitional && transitional.silentJSONParsing;
|
||||
var forcedJSONParsing = transitional && transitional.forcedJSONParsing;
|
||||
var strictJSONParsing = !silentJSONParsing && this.responseType === 'json';
|
||||
|
||||
if (strictJSONParsing || (forcedJSONParsing && utils.isString(data) && data.length)) {
|
||||
try {
|
||||
result = JSON.parse(result);
|
||||
} catch (e) { /* Ignore */ }
|
||||
return JSON.parse(data);
|
||||
} catch (e) {
|
||||
if (strictJSONParsing) {
|
||||
if (e.name === 'SyntaxError') {
|
||||
throw enhanceError(e, this, 'E_JSON_PARSE');
|
||||
}
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
}
|
||||
return result;
|
||||
|
||||
return data;
|
||||
}],
|
||||
|
||||
/**
|
||||
@@ -78,12 +114,12 @@ var defaults = {
|
||||
|
||||
validateStatus: function validateStatus(status) {
|
||||
return status >= 200 && status < 300;
|
||||
}
|
||||
};
|
||||
},
|
||||
|
||||
defaults.headers = {
|
||||
common: {
|
||||
'Accept': 'application/json, text/plain, */*'
|
||||
headers: {
|
||||
common: {
|
||||
'Accept': 'application/json, text/plain, */*'
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
Vendored
+3
@@ -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.
|
||||
Vendored
+3
@@ -0,0 +1,3 @@
|
||||
module.exports = {
|
||||
"version": "0.24.0"
|
||||
};
|
||||
@@ -1,5 +1,7 @@
|
||||
'use strict';
|
||||
|
||||
var utils = require('./../utils');
|
||||
|
||||
/**
|
||||
* Determines whether the payload is an error thrown by Axios
|
||||
*
|
||||
@@ -7,5 +9,5 @@
|
||||
* @returns {boolean} True if the payload is an error thrown by Axios, otherwise false
|
||||
*/
|
||||
module.exports = function isAxiosError(payload) {
|
||||
return (typeof payload === 'object') && (payload.isAxiosError === true);
|
||||
return utils.isObject(payload) && (payload.isAxiosError === true);
|
||||
};
|
||||
|
||||
@@ -0,0 +1,82 @@
|
||||
'use strict';
|
||||
|
||||
var VERSION = require('../env/data').version;
|
||||
|
||||
var validators = {};
|
||||
|
||||
// eslint-disable-next-line func-names
|
||||
['object', 'boolean', 'number', 'function', 'string', 'symbol'].forEach(function(type, i) {
|
||||
validators[type] = function validator(thing) {
|
||||
return typeof thing === type || 'a' + (i < 1 ? 'n ' : ' ') + type;
|
||||
};
|
||||
});
|
||||
|
||||
var deprecatedWarnings = {};
|
||||
|
||||
/**
|
||||
* Transitional option validator
|
||||
* @param {function|boolean?} validator - set to false if the transitional option has been removed
|
||||
* @param {string?} version - deprecated version / removed since version
|
||||
* @param {string?} message - some message with additional info
|
||||
* @returns {function}
|
||||
*/
|
||||
validators.transitional = function transitional(validator, version, message) {
|
||||
function formatMessage(opt, desc) {
|
||||
return '[Axios v' + VERSION + '] Transitional option \'' + opt + '\'' + desc + (message ? '. ' + message : '');
|
||||
}
|
||||
|
||||
// eslint-disable-next-line func-names
|
||||
return function(value, opt, opts) {
|
||||
if (validator === false) {
|
||||
throw new Error(formatMessage(opt, ' has been removed' + (version ? ' in ' + version : '')));
|
||||
}
|
||||
|
||||
if (version && !deprecatedWarnings[opt]) {
|
||||
deprecatedWarnings[opt] = true;
|
||||
// eslint-disable-next-line no-console
|
||||
console.warn(
|
||||
formatMessage(
|
||||
opt,
|
||||
' has been deprecated since v' + version + ' and will be removed in the near future'
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
return validator ? validator(value, opt, opts) : true;
|
||||
};
|
||||
};
|
||||
|
||||
/**
|
||||
* Assert object's properties type
|
||||
* @param {object} options
|
||||
* @param {object} schema
|
||||
* @param {boolean?} allowUnknown
|
||||
*/
|
||||
|
||||
function assertOptions(options, schema, allowUnknown) {
|
||||
if (typeof options !== 'object') {
|
||||
throw new TypeError('options must be an object');
|
||||
}
|
||||
var keys = Object.keys(options);
|
||||
var i = keys.length;
|
||||
while (i-- > 0) {
|
||||
var opt = keys[i];
|
||||
var validator = schema[opt];
|
||||
if (validator) {
|
||||
var value = options[opt];
|
||||
var result = value === undefined || validator(value, opt, options);
|
||||
if (result !== true) {
|
||||
throw new TypeError('option ' + opt + ' must be ' + result);
|
||||
}
|
||||
continue;
|
||||
}
|
||||
if (allowUnknown !== true) {
|
||||
throw Error('Unknown option ' + opt);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
assertOptions: assertOptions,
|
||||
validators: validators
|
||||
};
|
||||
+4
-4
@@ -54,7 +54,7 @@ function isArrayBuffer(val) {
|
||||
* @returns {boolean} True if value is an FormData, otherwise false
|
||||
*/
|
||||
function isFormData(val) {
|
||||
return (typeof FormData !== 'undefined') && (val instanceof FormData);
|
||||
return toString.call(val) === '[object FormData]';
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -68,7 +68,7 @@ function isArrayBufferView(val) {
|
||||
if ((typeof ArrayBuffer !== 'undefined') && (ArrayBuffer.isView)) {
|
||||
result = ArrayBuffer.isView(val);
|
||||
} else {
|
||||
result = (val) && (val.buffer) && (val.buffer instanceof ArrayBuffer);
|
||||
result = (val) && (val.buffer) && (isArrayBuffer(val.buffer));
|
||||
}
|
||||
return result;
|
||||
}
|
||||
@@ -175,7 +175,7 @@ function isStream(val) {
|
||||
* @returns {boolean} True if value is a URLSearchParams object, otherwise false
|
||||
*/
|
||||
function isURLSearchParams(val) {
|
||||
return typeof URLSearchParams !== 'undefined' && val instanceof URLSearchParams;
|
||||
return toString.call(val) === '[object URLSearchParams]';
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -185,7 +185,7 @@ function isURLSearchParams(val) {
|
||||
* @returns {String} The String freed of excess whitespace
|
||||
*/
|
||||
function trim(str) {
|
||||
return str.replace(/^\s*/, '').replace(/\s*$/, '');
|
||||
return str.trim ? str.trim() : str.replace(/^\s+|\s+$/g, '');
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
+9
-7
@@ -1,14 +1,15 @@
|
||||
{
|
||||
"name": "axios",
|
||||
"version": "0.21.1",
|
||||
"version": "0.24.0",
|
||||
"description": "Promise based HTTP client for the browser and node.js",
|
||||
"main": "index.js",
|
||||
"types": "index.d.ts",
|
||||
"scripts": {
|
||||
"test": "grunt test",
|
||||
"test": "grunt test && dtslint",
|
||||
"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",
|
||||
"preversion": "grunt version && npm test",
|
||||
"version": "npm run build && 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",
|
||||
@@ -32,7 +33,9 @@
|
||||
},
|
||||
"homepage": "https://axios-http.com",
|
||||
"devDependencies": {
|
||||
"abortcontroller-polyfill": "^1.5.0",
|
||||
"coveralls": "^3.0.0",
|
||||
"dtslint": "^4.1.6",
|
||||
"es6-promise": "^4.2.4",
|
||||
"grunt": "^1.3.0",
|
||||
"grunt-banner": "^0.6.0",
|
||||
@@ -42,7 +45,6 @@
|
||||
"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",
|
||||
@@ -52,7 +54,7 @@
|
||||
"karma-jasmine": "^1.1.1",
|
||||
"karma-jasmine-ajax": "^0.1.13",
|
||||
"karma-safari-launcher": "^1.0.0",
|
||||
"karma-sauce-launcher": "^4.3.5",
|
||||
"karma-sauce-launcher": "^4.3.6",
|
||||
"karma-sinon": "^1.0.5",
|
||||
"karma-sourcemap-loader": "^0.3.8",
|
||||
"karma-webpack": "^4.0.2",
|
||||
@@ -73,7 +75,7 @@
|
||||
"unpkg": "dist/axios.min.js",
|
||||
"typings": "./index.d.ts",
|
||||
"dependencies": {
|
||||
"follow-redirects": "^1.13.3"
|
||||
"follow-redirects": "^1.14.4"
|
||||
},
|
||||
"bundlesize": [
|
||||
{
|
||||
|
||||
+9
-1
@@ -5,7 +5,6 @@
|
||||
<link rel="stylesheet" type="text/css" href="//maxcdn.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css"/>
|
||||
<style type="text/css">
|
||||
pre {
|
||||
max-height: 200px;
|
||||
min-height: 39px;
|
||||
overflow: auto;
|
||||
}
|
||||
@@ -58,6 +57,11 @@
|
||||
<pre id="response">No Data</pre>
|
||||
</div>
|
||||
|
||||
<div class="well">
|
||||
<h3>Error</h3>
|
||||
<pre id="error">None</pre>
|
||||
</div>
|
||||
|
||||
<script src="/axios.js"></script>
|
||||
<script>
|
||||
(function () {
|
||||
@@ -81,6 +85,7 @@
|
||||
var submit = document.getElementById('submit');
|
||||
var request = document.getElementById('request');
|
||||
var response = document.getElementById('response');
|
||||
var error = document.getElementById('error');
|
||||
|
||||
function acceptsData(method) {
|
||||
return ['PATCH', 'POST', 'PUT'].indexOf(method) > -1;
|
||||
@@ -138,8 +143,11 @@
|
||||
axios(options)
|
||||
.then(function (res) {
|
||||
response.innerHTML = JSON.stringify(res.data, null, 2);
|
||||
error.innerHTML = "None";
|
||||
})
|
||||
.catch(function (res) {
|
||||
error.innerHTML = JSON.stringify(res.toJSON(), null, 2)
|
||||
console.error('Axios caught an error from request', res.toJSON());
|
||||
response.innerHTML = JSON.stringify(res.data, null, 2);
|
||||
});
|
||||
};
|
||||
|
||||
+40
-11
@@ -1,5 +1,8 @@
|
||||
var Cancel = axios.Cancel;
|
||||
var CancelToken = axios.CancelToken;
|
||||
var _AbortController = require('abortcontroller-polyfill/dist/cjs-ponyfill.js').AbortController;
|
||||
|
||||
var AbortController = typeof AbortController === 'function' ? AbortController : _AbortController;
|
||||
|
||||
describe('cancel', function() {
|
||||
beforeEach(function() {
|
||||
@@ -11,12 +14,12 @@ describe('cancel', 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();
|
||||
source.cancel('Operation has been canceled.');
|
||||
axios.get('/foo', {
|
||||
cancelToken: source.token
|
||||
}).catch(function (thrown) {
|
||||
}).catch(function(thrown) {
|
||||
expect(thrown).toEqual(jasmine.any(Cancel));
|
||||
expect(thrown.message).toBe('Operation has been canceled.');
|
||||
done();
|
||||
@@ -25,17 +28,17 @@ describe('cancel', 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();
|
||||
axios.get('/foo/bar', {
|
||||
cancelToken: source.token
|
||||
}).catch(function (thrown) {
|
||||
}).catch(function(thrown) {
|
||||
expect(thrown).toEqual(jasmine.any(Cancel));
|
||||
expect(thrown.message).toBe('Operation has been canceled.');
|
||||
done();
|
||||
});
|
||||
|
||||
getAjaxRequest().then(function (request) {
|
||||
getAjaxRequest().then(function(request) {
|
||||
// call cancel() when the request has been sent, but a response has not been received
|
||||
source.cancel('Operation has been canceled.');
|
||||
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 request;
|
||||
axios.get('/foo/bar', {
|
||||
@@ -56,7 +59,7 @@ describe('cancel', function() {
|
||||
done();
|
||||
});
|
||||
|
||||
getAjaxRequest().then(function (req) {
|
||||
getAjaxRequest().then(function(req) {
|
||||
// call cancel() when the request has been sent, but a response has not been received
|
||||
source.cancel();
|
||||
request = req;
|
||||
@@ -66,19 +69,19 @@ describe('cancel', function() {
|
||||
|
||||
describe('when called after response has been received', function() {
|
||||
// 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();
|
||||
axios.get('/foo', {
|
||||
cancelToken: source.token
|
||||
}).then(function () {
|
||||
window.addEventListener('unhandledrejection', function () {
|
||||
}).then(function() {
|
||||
window.addEventListener('unhandledrejection', function() {
|
||||
done.fail('Unhandled rejection.');
|
||||
});
|
||||
source.cancel();
|
||||
setTimeout(done, 100);
|
||||
});
|
||||
|
||||
getAjaxRequest().then(function (request) {
|
||||
getAjaxRequest().then(function(request) {
|
||||
request.respondWith({
|
||||
status: 200,
|
||||
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);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
@@ -23,6 +23,7 @@ describe('core::createError', function() {
|
||||
expect(json.message).toBe('Boom!');
|
||||
expect(json.config).toEqual({ foo: 'bar' });
|
||||
expect(json.code).toBe('ESOMETHING');
|
||||
expect(json.status).toBe(200);
|
||||
expect(json.request).toBe(undefined);
|
||||
expect(json.response).toBe(undefined);
|
||||
});
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
var enhanceError = require('../../../lib/core/enhanceError');
|
||||
|
||||
describe('core::enhanceError', function() {
|
||||
it('should add config, config, request and response to error', function() {
|
||||
it('should add config, code, request, response, and toJSON function to error', function() {
|
||||
var error = new Error('Boom!');
|
||||
var request = { path: '/foo' };
|
||||
var response = { status: 200, data: { foo: 'bar' } };
|
||||
@@ -11,9 +11,19 @@ describe('core::enhanceError', function() {
|
||||
expect(error.code).toBe('ESOMETHING');
|
||||
expect(error.request).toBe(request);
|
||||
expect(error.response).toBe(response);
|
||||
expect(typeof error.toJSON).toBe('function');
|
||||
expect(error.isAxiosError).toBe(true);
|
||||
});
|
||||
|
||||
it('should serialize to JSON with a status of null when there is no response', function() {
|
||||
var error = new Error('Boom!');
|
||||
var request = { path: '/foo' };
|
||||
var response = undefined;
|
||||
|
||||
var errorAsJson = enhanceError(error, { foo: 'bar' }, 'ESOMETHING', request, response).toJSON();
|
||||
expect(errorAsJson.status).toEqual(null);
|
||||
});
|
||||
|
||||
it('should return error', function() {
|
||||
var error = new Error('Boom!');
|
||||
expect(enhanceError(error, { foo: 'bar' }, 'ESOMETHING')).toBe(error);
|
||||
|
||||
@@ -20,12 +20,25 @@ describe('defaults', function () {
|
||||
expect(defaults.transformRequest[0]({foo: 'bar'})).toEqual('{"foo":"bar"}');
|
||||
});
|
||||
|
||||
it("should also transform request json when 'Content-Type' is 'application/json'", function () {
|
||||
var headers = {
|
||||
'Content-Type': 'application/json',
|
||||
};
|
||||
expect(defaults.transformRequest[0](JSON.stringify({ foo: 'bar' }), headers)).toEqual('{"foo":"bar"}');
|
||||
expect(defaults.transformRequest[0]([42, 43], headers)).toEqual('[42,43]');
|
||||
expect(defaults.transformRequest[0]('foo', headers)).toEqual('"foo"');
|
||||
expect(defaults.transformRequest[0](42, headers)).toEqual('42');
|
||||
expect(defaults.transformRequest[0](true, headers)).toEqual('true');
|
||||
expect(defaults.transformRequest[0](false, headers)).toEqual('false');
|
||||
expect(defaults.transformRequest[0](null, headers)).toEqual('null');
|
||||
});
|
||||
|
||||
it('should do nothing to request string', function () {
|
||||
expect(defaults.transformRequest[0]('foo=bar')).toEqual('foo=bar');
|
||||
});
|
||||
|
||||
it('should transform response json', function () {
|
||||
var data = defaults.transformResponse[0]('{"foo":"bar"}');
|
||||
var data = defaults.transformResponse[0].call(defaults, '{"foo":"bar"}');
|
||||
|
||||
expect(typeof data).toEqual('object');
|
||||
expect(data.foo).toEqual('bar');
|
||||
|
||||
@@ -90,7 +90,7 @@ describe('headers', function () {
|
||||
});
|
||||
|
||||
getAjaxRequest().then(function (request) {
|
||||
testHeaderValue(request.requestHeaders, 'Content-Type', 'application/json;charset=utf-8');
|
||||
testHeaderValue(request.requestHeaders, 'Content-Type', 'application/json');
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
@@ -17,4 +17,9 @@ describe('helpers::isAxiosError', function () {
|
||||
expect(isAxiosError(new Error('Boom!')))
|
||||
.toBe(false);
|
||||
});
|
||||
|
||||
it('should return false if the error is null', function () {
|
||||
expect(isAxiosError(null))
|
||||
.toBe(false);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -0,0 +1,43 @@
|
||||
'use strict';
|
||||
|
||||
var validator = require('../../../lib/helpers/validator');
|
||||
|
||||
describe('validator::assertOptions', function() {
|
||||
it('should throw only if unknown an option was passed', function() {
|
||||
expect(function() {
|
||||
validator.assertOptions({
|
||||
x: true
|
||||
}, {
|
||||
y: validator.validators.boolean
|
||||
});
|
||||
}).toThrow(new Error('Unknown option x'));
|
||||
|
||||
expect(function() {
|
||||
validator.assertOptions({
|
||||
x: true
|
||||
}, {
|
||||
x: validator.validators.boolean,
|
||||
y: validator.validators.boolean
|
||||
});
|
||||
}).not.toThrow(new Error('Unknown option x'));
|
||||
});
|
||||
|
||||
it('should throw TypeError only if option type doesn\'t match', function() {
|
||||
expect(function() {
|
||||
validator.assertOptions({
|
||||
x: 123
|
||||
}, {
|
||||
x: validator.validators.boolean
|
||||
});
|
||||
}).toThrow(new TypeError('option x must be a boolean'));
|
||||
|
||||
expect(function() {
|
||||
validator.assertOptions({
|
||||
x: true
|
||||
}, {
|
||||
x: validator.validators.boolean,
|
||||
y: validator.validators.boolean
|
||||
});
|
||||
}).not.toThrow();
|
||||
});
|
||||
});
|
||||
@@ -20,6 +20,7 @@ describe('instance', function () {
|
||||
'all',
|
||||
'spread',
|
||||
'isAxiosError',
|
||||
'VERSION',
|
||||
'default'].indexOf(prop) > -1) {
|
||||
continue;
|
||||
}
|
||||
|
||||
+161
-25
@@ -252,6 +252,35 @@ describe('interceptors', function () {
|
||||
});
|
||||
});
|
||||
|
||||
it('should add a response interceptor when request interceptor is defined', function (done) {
|
||||
var response;
|
||||
|
||||
axios.interceptors.request.use(function (data) {
|
||||
return data;
|
||||
});
|
||||
|
||||
axios.interceptors.response.use(function (data) {
|
||||
data.data = data.data + ' - modified by interceptor';
|
||||
return data;
|
||||
});
|
||||
|
||||
axios('/foo').then(function (data) {
|
||||
response = data;
|
||||
});
|
||||
|
||||
getAjaxRequest().then(function (request) {
|
||||
request.respondWith({
|
||||
status: 200,
|
||||
responseText: 'OK'
|
||||
});
|
||||
|
||||
setTimeout(function () {
|
||||
expect(response.data).toBe('OK - modified by interceptor');
|
||||
done();
|
||||
}, 100);
|
||||
});
|
||||
});
|
||||
|
||||
it('should add a response interceptor that returns a new data object', function (done) {
|
||||
var response;
|
||||
|
||||
@@ -308,36 +337,143 @@ describe('interceptors', function () {
|
||||
});
|
||||
});
|
||||
|
||||
it('should add multiple response interceptors', function (done) {
|
||||
var response;
|
||||
describe('given you add multiple response interceptors', function () {
|
||||
|
||||
axios.interceptors.response.use(function (data) {
|
||||
data.data = data.data + '1';
|
||||
return data;
|
||||
});
|
||||
axios.interceptors.response.use(function (data) {
|
||||
data.data = data.data + '2';
|
||||
return data;
|
||||
});
|
||||
axios.interceptors.response.use(function (data) {
|
||||
data.data = data.data + '3';
|
||||
return data;
|
||||
});
|
||||
describe('and when the response was fulfilled', function () {
|
||||
|
||||
axios('/foo').then(function (data) {
|
||||
response = data;
|
||||
});
|
||||
function fireRequestAndExpect(expectation) {
|
||||
var response;
|
||||
axios('/foo').then(function(data) {
|
||||
response = data;
|
||||
});
|
||||
getAjaxRequest().then(function (request) {
|
||||
request.respondWith({
|
||||
status: 200,
|
||||
responseText: 'OK'
|
||||
});
|
||||
|
||||
getAjaxRequest().then(function (request) {
|
||||
request.respondWith({
|
||||
status: 200,
|
||||
responseText: 'OK'
|
||||
setTimeout(function() {
|
||||
expectation(response)
|
||||
}, 100);
|
||||
});
|
||||
}
|
||||
|
||||
it('then each interceptor is executed', function (done) {
|
||||
var interceptor1 = jasmine.createSpy('interceptor1');
|
||||
var interceptor2 = jasmine.createSpy('interceptor2');
|
||||
axios.interceptors.response.use(interceptor1);
|
||||
axios.interceptors.response.use(interceptor2);
|
||||
|
||||
fireRequestAndExpect(function () {
|
||||
expect(interceptor1).toHaveBeenCalled();
|
||||
expect(interceptor2).toHaveBeenCalled();
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
setTimeout(function () {
|
||||
expect(response.data).toBe('OK123');
|
||||
done();
|
||||
}, 100);
|
||||
it('then they are executed in the order they were added', function (done) {
|
||||
var interceptor1 = jasmine.createSpy('interceptor1');
|
||||
var interceptor2 = jasmine.createSpy('interceptor2');
|
||||
axios.interceptors.response.use(interceptor1);
|
||||
axios.interceptors.response.use(interceptor2);
|
||||
|
||||
fireRequestAndExpect(function () {
|
||||
expect(interceptor1).toHaveBeenCalledBefore(interceptor2);
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('then only the last interceptor\'s result is returned', function (done) {
|
||||
axios.interceptors.response.use(function() {
|
||||
return 'response 1';
|
||||
});
|
||||
axios.interceptors.response.use(function() {
|
||||
return 'response 2';
|
||||
});
|
||||
|
||||
fireRequestAndExpect(function (response) {
|
||||
expect(response).toBe('response 2');
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('then every interceptor receives the result of it\'s predecessor', function (done) {
|
||||
axios.interceptors.response.use(function() {
|
||||
return 'response 1';
|
||||
});
|
||||
axios.interceptors.response.use(function(response) {
|
||||
return [response, 'response 2'];
|
||||
});
|
||||
|
||||
fireRequestAndExpect(function (response) {
|
||||
expect(response).toEqual(['response 1', 'response 2']);
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
describe('and when the fulfillment-interceptor throws', function () {
|
||||
|
||||
function fireRequestCatchAndExpect(expectation) {
|
||||
axios('/foo').catch(function(data) {
|
||||
// dont handle result
|
||||
});
|
||||
getAjaxRequest().then(function (request) {
|
||||
request.respondWith({
|
||||
status: 200,
|
||||
responseText: 'OK'
|
||||
});
|
||||
|
||||
setTimeout(function() {
|
||||
expectation()
|
||||
}, 100);
|
||||
});
|
||||
}
|
||||
|
||||
it('then the following fulfillment-interceptor is not called', function (done) {
|
||||
axios.interceptors.response.use(function() {
|
||||
throw Error('throwing interceptor');
|
||||
});
|
||||
var interceptor2 = jasmine.createSpy('interceptor2');
|
||||
axios.interceptors.response.use(interceptor2);
|
||||
|
||||
fireRequestCatchAndExpect(function () {
|
||||
expect(interceptor2).not.toHaveBeenCalled();
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('then the following rejection-interceptor is called', function (done) {
|
||||
axios.interceptors.response.use(function() {
|
||||
throw Error('throwing interceptor');
|
||||
});
|
||||
var unusedFulfillInterceptor = function() {};
|
||||
var rejectIntercept = jasmine.createSpy('rejectIntercept');
|
||||
axios.interceptors.response.use(unusedFulfillInterceptor, rejectIntercept);
|
||||
|
||||
fireRequestCatchAndExpect(function () {
|
||||
expect(rejectIntercept).toHaveBeenCalled();
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('once caught, another following fulfill-interceptor is called again (just like in a promise chain)', function (done) {
|
||||
axios.interceptors.response.use(function() {
|
||||
throw Error('throwing interceptor');
|
||||
});
|
||||
|
||||
var unusedFulfillInterceptor = function() {};
|
||||
var catchingThrowingInterceptor = function() {};
|
||||
axios.interceptors.response.use(unusedFulfillInterceptor, catchingThrowingInterceptor);
|
||||
|
||||
var interceptor3 = jasmine.createSpy('interceptor3');
|
||||
axios.interceptors.response.use(interceptor3);
|
||||
|
||||
fireRequestCatchAndExpect(function () {
|
||||
expect(interceptor3).toHaveBeenCalled();
|
||||
done();
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
@@ -63,6 +63,51 @@ describe('requests', function () {
|
||||
});
|
||||
});
|
||||
|
||||
describe('timeouts', function(){
|
||||
beforeEach(function () {
|
||||
jasmine.clock().install();
|
||||
});
|
||||
|
||||
afterEach(function () {
|
||||
jasmine.clock().uninstall();
|
||||
});
|
||||
|
||||
it('should handle timeouts', function (done) {
|
||||
axios({
|
||||
url: '/foo',
|
||||
timeout: 100
|
||||
}).then(function () {
|
||||
fail(new Error('timeout error not caught'));
|
||||
}, function (err) {
|
||||
expect(err instanceof Error).toBe(true);
|
||||
expect(err.code).toEqual('ECONNABORTED');
|
||||
done();
|
||||
});
|
||||
|
||||
jasmine.Ajax.requests.mostRecent().responseTimeout();
|
||||
});
|
||||
|
||||
describe('transitional.clarifyTimeoutError', function () {
|
||||
it('should activate throwing ETIMEDOUT instead of ECONNABORTED on request timeouts', function (done) {
|
||||
axios({
|
||||
url: '/foo',
|
||||
timeout: 100,
|
||||
transitional: {
|
||||
clarifyTimeoutError: true
|
||||
}
|
||||
}).then(function () {
|
||||
fail(new Error('timeout error not caught'));
|
||||
}, function (err) {
|
||||
expect(err instanceof Error).toBe(true);
|
||||
expect(err.code).toEqual('ETIMEDOUT');
|
||||
done();
|
||||
});
|
||||
|
||||
jasmine.Ajax.requests.mostRecent().responseTimeout();
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
it('should reject on network errors', function (done) {
|
||||
// disable jasmine.Ajax since we're hitting a non-existent server anyway
|
||||
jasmine.Ajax.uninstall();
|
||||
|
||||
@@ -41,6 +41,89 @@ describe('transform', function () {
|
||||
});
|
||||
});
|
||||
|
||||
it('should throw a SyntaxError if JSON parsing failed and responseType is "json" if silentJSONParsing is false',
|
||||
function (done) {
|
||||
var thrown;
|
||||
|
||||
axios({
|
||||
url: '/foo',
|
||||
responseType: 'json',
|
||||
transitional: {silentJSONParsing: false}
|
||||
}).then(function () {
|
||||
done(new Error('should fail'));
|
||||
}, function (err) {
|
||||
thrown = err;
|
||||
});
|
||||
|
||||
getAjaxRequest().then(function (request) {
|
||||
request.respondWith({
|
||||
status: 200,
|
||||
responseText: '{foo": "bar"}' // JSON SyntaxError
|
||||
});
|
||||
|
||||
setTimeout(function () {
|
||||
expect(thrown).toBeTruthy();
|
||||
expect(thrown.name).toContain('SyntaxError');
|
||||
done();
|
||||
}, 100);
|
||||
});
|
||||
}
|
||||
);
|
||||
|
||||
it('should send data as JSON if request content-type is application/json', function (done) {
|
||||
var response;
|
||||
|
||||
axios.post('/foo', 123, {headers: {'Content-Type': 'application/json'}}).then(function (_response) {
|
||||
response = _response;
|
||||
}, function (err) {
|
||||
done(err);
|
||||
});
|
||||
|
||||
getAjaxRequest().then(function (request) {
|
||||
request.respondWith({
|
||||
status: 200,
|
||||
responseText: ''
|
||||
});
|
||||
|
||||
setTimeout(function () {
|
||||
expect(response).toBeTruthy();
|
||||
expect(request.requestHeaders['Content-Type']).toBe('application/json');
|
||||
expect(JSON.parse(request.params)).toBe(123);
|
||||
done();
|
||||
}, 100);
|
||||
});
|
||||
});
|
||||
|
||||
it('should not assume JSON if responseType is not `json`', function (done) {
|
||||
var response;
|
||||
|
||||
axios.get('/foo', {
|
||||
responseType: 'text',
|
||||
transitional: {
|
||||
forcedJSONParsing: false
|
||||
}
|
||||
}).then(function (_response) {
|
||||
response = _response;
|
||||
}, function (err) {
|
||||
done(err);
|
||||
});
|
||||
|
||||
var rawData = '{"x":1}';
|
||||
|
||||
getAjaxRequest().then(function (request) {
|
||||
request.respondWith({
|
||||
status: 200,
|
||||
responseText: rawData
|
||||
});
|
||||
|
||||
setTimeout(function () {
|
||||
expect(response).toBeTruthy();
|
||||
expect(response.data).toBe(rawData);
|
||||
done();
|
||||
}, 100);
|
||||
});
|
||||
});
|
||||
|
||||
it('should override default transform', function (done) {
|
||||
var data = {
|
||||
foo: 'bar'
|
||||
|
||||
+18
-14
@@ -8,7 +8,7 @@ import axios, {
|
||||
CancelToken,
|
||||
CancelTokenSource,
|
||||
Canceler
|
||||
} from '../../';
|
||||
} from 'axios';
|
||||
|
||||
const config: AxiosRequestConfig = {
|
||||
url: '/user',
|
||||
@@ -111,6 +111,10 @@ axios.patch('/user', { foo: 'bar' })
|
||||
.catch(handleError);
|
||||
|
||||
// Typed methods
|
||||
interface UserCreationDef {
|
||||
name: string;
|
||||
}
|
||||
|
||||
interface User {
|
||||
id: number;
|
||||
name: string;
|
||||
@@ -138,7 +142,7 @@ axios.get<User>('/user', { params: { id: 12345 } })
|
||||
axios.head<User>('/user')
|
||||
.then(handleUserResponse)
|
||||
.catch(handleError);
|
||||
|
||||
|
||||
axios.options<User>('/user')
|
||||
.then(handleUserResponse)
|
||||
.catch(handleError);
|
||||
@@ -147,27 +151,27 @@ axios.delete<User>('/user')
|
||||
.then(handleUserResponse)
|
||||
.catch(handleError);
|
||||
|
||||
axios.post<User>('/user', { foo: 'bar' })
|
||||
axios.post<User>('/user', { name: 'foo', id: 1 })
|
||||
.then(handleUserResponse)
|
||||
.catch(handleError);
|
||||
|
||||
axios.post<User>('/user', { foo: 'bar' }, { headers: { 'X-FOO': 'bar' } })
|
||||
axios.post<User>('/user', { name: 'foo', id: 1 }, { headers: { 'X-FOO': 'bar' } })
|
||||
.then(handleUserResponse)
|
||||
.catch(handleError);
|
||||
|
||||
axios.put<User>('/user', { foo: 'bar' })
|
||||
axios.put<User>('/user', { name: 'foo', id: 1 })
|
||||
.then(handleUserResponse)
|
||||
.catch(handleError);
|
||||
|
||||
axios.patch<User>('/user', { foo: 'bar' })
|
||||
axios.patch<User>('/user', { name: 'foo', id: 1 })
|
||||
.then(handleUserResponse)
|
||||
.catch(handleError);
|
||||
|
||||
// (Typed methods) with custom response type
|
||||
|
||||
const handleStringResponse = (response: string) => {
|
||||
console.log(response)
|
||||
}
|
||||
console.log(response);
|
||||
};
|
||||
|
||||
axios.get<User, string>('/user?id=12345')
|
||||
.then(handleStringResponse)
|
||||
@@ -189,19 +193,19 @@ axios.delete<User, string>('/user')
|
||||
.then(handleStringResponse)
|
||||
.catch(handleError);
|
||||
|
||||
axios.post<User, string>('/user', { foo: 'bar' })
|
||||
axios.post<Partial<UserCreationDef>, string>('/user', { name: 'foo' })
|
||||
.then(handleStringResponse)
|
||||
.catch(handleError);
|
||||
|
||||
axios.post<User, string>('/user', { foo: 'bar' }, { headers: { 'X-FOO': 'bar' } })
|
||||
axios.post<Partial<UserCreationDef>, string>('/user', { name: 'foo' }, { headers: { 'X-FOO': 'bar' } })
|
||||
.then(handleStringResponse)
|
||||
.catch(handleError);
|
||||
|
||||
axios.put<User, string>('/user', { foo: 'bar' })
|
||||
axios.put<Partial<UserCreationDef>, string>('/user', { name: 'foo' })
|
||||
.then(handleStringResponse)
|
||||
.catch(handleError);
|
||||
|
||||
axios.patch<User, string>('/user', { foo: 'bar' })
|
||||
axios.patch<Partial<UserCreationDef>, string>('/user', { name: 'foo' })
|
||||
.then(handleStringResponse)
|
||||
.catch(handleError);
|
||||
|
||||
@@ -338,11 +342,11 @@ axios.get('/user')
|
||||
|
||||
axios.get('/user')
|
||||
.catch((error: any) => 'foo')
|
||||
.then((value: string) => {});
|
||||
.then((value) => {});
|
||||
|
||||
axios.get('/user')
|
||||
.catch((error: any) => Promise.resolve('foo'))
|
||||
.then((value: string) => {});
|
||||
.then((value) => {});
|
||||
|
||||
// Cancellation
|
||||
|
||||
|
||||
+131
-8
@@ -18,7 +18,7 @@ describe('supports http with nodejs', function () {
|
||||
server = null;
|
||||
}
|
||||
if (proxy) {
|
||||
proxy.close()
|
||||
proxy.close();
|
||||
proxy = null;
|
||||
}
|
||||
if (process.env.http_proxy) {
|
||||
@@ -29,6 +29,64 @@ describe('supports http with nodejs', function () {
|
||||
}
|
||||
});
|
||||
|
||||
it('should throw an error if the timeout property is not parsable as a number', function (done) {
|
||||
|
||||
server = http.createServer(function (req, res) {
|
||||
setTimeout(function () {
|
||||
res.end();
|
||||
}, 1000);
|
||||
}).listen(4444, function () {
|
||||
var success = false, failure = false;
|
||||
var error;
|
||||
|
||||
axios.get('http://localhost:4444/', {
|
||||
timeout: { strangeTimeout: 250 }
|
||||
}).then(function (res) {
|
||||
success = true;
|
||||
}).catch(function (err) {
|
||||
error = err;
|
||||
failure = true;
|
||||
});
|
||||
|
||||
setTimeout(function () {
|
||||
assert.equal(success, false, 'request should not succeed');
|
||||
assert.equal(failure, true, 'request should fail');
|
||||
assert.equal(error.code, 'ERR_PARSE_TIMEOUT');
|
||||
assert.equal(error.message, 'error trying to parse `config.timeout` to int');
|
||||
done();
|
||||
}, 300);
|
||||
});
|
||||
});
|
||||
|
||||
it('should parse the timeout property', function (done) {
|
||||
|
||||
server = http.createServer(function (req, res) {
|
||||
setTimeout(function () {
|
||||
res.end();
|
||||
}, 1000);
|
||||
}).listen(4444, function () {
|
||||
var success = false, failure = false;
|
||||
var error;
|
||||
|
||||
axios.get('http://localhost:4444/', {
|
||||
timeout: '250'
|
||||
}).then(function (res) {
|
||||
success = true;
|
||||
}).catch(function (err) {
|
||||
error = err;
|
||||
failure = true;
|
||||
});
|
||||
|
||||
setTimeout(function () {
|
||||
assert.equal(success, false, 'request should not succeed');
|
||||
assert.equal(failure, true, 'request should fail');
|
||||
assert.equal(error.code, 'ECONNABORTED');
|
||||
assert.equal(error.message, 'timeout of 250ms exceeded');
|
||||
done();
|
||||
}, 300);
|
||||
});
|
||||
});
|
||||
|
||||
it('should respect the timeout property', function (done) {
|
||||
|
||||
server = http.createServer(function (req, res) {
|
||||
@@ -66,7 +124,7 @@ describe('supports http with nodejs', function () {
|
||||
};
|
||||
|
||||
server = http.createServer(function (req, res) {
|
||||
res.setHeader('Content-Type', 'application/json;charset=utf-8');
|
||||
res.setHeader('Content-Type', 'application/json');
|
||||
res.end(JSON.stringify(data));
|
||||
}).listen(4444, function () {
|
||||
axios.get('http://localhost:4444/').then(function (res) {
|
||||
@@ -84,7 +142,7 @@ describe('supports http with nodejs', function () {
|
||||
};
|
||||
|
||||
server = http.createServer(function (req, res) {
|
||||
res.setHeader('Content-Type', 'application/json;charset=utf-8');
|
||||
res.setHeader('Content-Type', 'application/json');
|
||||
var bomBuffer = Buffer.from([0xEF, 0xBB, 0xBF])
|
||||
var jsonBuffer = Buffer.from(JSON.stringify(data));
|
||||
res.end(Buffer.concat([bomBuffer, jsonBuffer]));
|
||||
@@ -189,7 +247,7 @@ describe('supports http with nodejs', function () {
|
||||
zlib.gzip(JSON.stringify(data), function (err, zipped) {
|
||||
|
||||
server = http.createServer(function (req, res) {
|
||||
res.setHeader('Content-Type', 'application/json;charset=utf-8');
|
||||
res.setHeader('Content-Type', 'application/json');
|
||||
res.setHeader('Content-Encoding', 'gzip');
|
||||
res.end(zipped);
|
||||
}).listen(4444, function () {
|
||||
@@ -204,7 +262,7 @@ describe('supports http with nodejs', function () {
|
||||
|
||||
it('should support gunzip error handling', function (done) {
|
||||
server = http.createServer(function (req, res) {
|
||||
res.setHeader('Content-Type', 'application/json;charset=utf-8');
|
||||
res.setHeader('Content-Type', 'application/json');
|
||||
res.setHeader('Content-Encoding', 'gzip');
|
||||
res.end('invalid response');
|
||||
}).listen(4444, function () {
|
||||
@@ -268,7 +326,7 @@ describe('supports http with nodejs', function () {
|
||||
res.end(req.headers.authorization);
|
||||
}).listen(4444, function () {
|
||||
var auth = { username: 'foo', password: 'bar' };
|
||||
var headers = { Authorization: 'Bearer 1234' };
|
||||
var headers = { AuThOrIzAtIoN: 'Bearer 1234' }; // wonky casing to ensure caseless comparison
|
||||
axios.get('http://localhost:4444/', { auth: auth, headers: headers }).then(function (res) {
|
||||
var base64 = Buffer.from('foo:bar', 'utf8').toString('base64');
|
||||
assert.equal(res.data, 'Basic ' + base64);
|
||||
@@ -277,6 +335,41 @@ describe('supports http with nodejs', function () {
|
||||
});
|
||||
});
|
||||
|
||||
it('should provides a default User-Agent header', function (done) {
|
||||
server = http.createServer(function (req, res) {
|
||||
res.end(req.headers['user-agent']);
|
||||
}).listen(4444, function () {
|
||||
axios.get('http://localhost:4444/').then(function (res) {
|
||||
assert.ok(/^axios\/[\d.]+$/.test(res.data), `User-Agent header does not match: ${res.data}`);
|
||||
done();
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
it('should allow the User-Agent header to be overridden', function (done) {
|
||||
server = http.createServer(function (req, res) {
|
||||
res.end(req.headers['user-agent']);
|
||||
}).listen(4444, function () {
|
||||
var headers = { 'UsEr-AgEnT': 'foo bar' }; // wonky casing to ensure caseless comparison
|
||||
axios.get('http://localhost:4444/', { headers }).then(function (res) {
|
||||
assert.equal(res.data, 'foo bar');
|
||||
done();
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
it('should allow the Content-Length header to be overridden', function (done) {
|
||||
server = http.createServer(function (req, res) {
|
||||
assert.strictEqual(req.headers['content-length'], '42');
|
||||
res.end();
|
||||
}).listen(4444, function () {
|
||||
var headers = { 'CoNtEnT-lEnGtH': '42' }; // wonky casing to ensure caseless comparison
|
||||
axios.post('http://localhost:4444/', 'foo', { headers }).then(function () {
|
||||
done();
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
it('should support max content length', function (done) {
|
||||
var str = Array(100000).join('ж');
|
||||
|
||||
@@ -363,7 +456,6 @@ describe('supports http with nodejs', function () {
|
||||
setTimeout(function () {
|
||||
assert.equal(success, false, 'request should not succeed');
|
||||
assert.equal(failure, true, 'request should fail');
|
||||
assert.equal(error.code, 'ERR_FR_MAX_BODY_LENGTH_EXCEEDED');
|
||||
assert.equal(error.message, 'Request body larger than maxBodyLength limit');
|
||||
done();
|
||||
}, 100);
|
||||
@@ -860,7 +952,7 @@ describe('supports http with nodejs', function () {
|
||||
axios.get('http://localhost:4444/', {
|
||||
cancelToken: source.token
|
||||
}).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.');
|
||||
done();
|
||||
});
|
||||
@@ -910,5 +1002,36 @@ describe('supports http with nodejs', function () {
|
||||
});
|
||||
});
|
||||
|
||||
it('should throw an error if http server that aborts a chunked request', function (done) {
|
||||
server = http.createServer(function (req, res) {
|
||||
res.writeHead(200, { 'Content-Type': 'text/plain' });
|
||||
res.write('chunk 1');
|
||||
setTimeout(function () {
|
||||
res.write('chunk 2');
|
||||
}, 100);
|
||||
setTimeout(function() {
|
||||
res.destroy();
|
||||
}, 200);
|
||||
}).listen(4444, function () {
|
||||
var success = false, failure = false;
|
||||
var error;
|
||||
|
||||
axios.get('http://localhost:4444/aborted', {
|
||||
timeout: 500
|
||||
}).then(function (res) {
|
||||
success = true;
|
||||
}).catch(function (err) {
|
||||
error = err;
|
||||
failure = true;
|
||||
}).finally(function () {
|
||||
assert.strictEqual(success, false, 'request should not succeed');
|
||||
assert.strictEqual(failure, true, 'request should fail');
|
||||
assert.strictEqual(error.code, 'ERR_REQUEST_ABORTED');
|
||||
assert.strictEqual(error.message, 'error request aborted');
|
||||
done();
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
|
||||
@@ -27,4 +27,4 @@ describe('transformResponse', function () {
|
||||
assert.strictEqual(result, data);
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
@@ -0,0 +1,14 @@
|
||||
{
|
||||
"compilerOptions": {
|
||||
"module": "es2015",
|
||||
"lib": ["dom", "es2015"],
|
||||
"types": [],
|
||||
"moduleResolution": "node",
|
||||
"strict": true,
|
||||
"noEmit": true,
|
||||
"baseUrl": ".",
|
||||
"paths": {
|
||||
"axios": ["."]
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
{
|
||||
"extends": "dtslint/dtslint.json",
|
||||
"rules": {
|
||||
"no-unnecessary-generics": false
|
||||
}
|
||||
}
|
||||
+2
-1
@@ -11,7 +11,8 @@ function generateConfig(name) {
|
||||
filename: name + '.js',
|
||||
sourceMapFilename: name + '.map',
|
||||
library: 'axios',
|
||||
libraryTarget: 'umd'
|
||||
libraryTarget: 'umd',
|
||||
globalObject: 'this'
|
||||
},
|
||||
node: {
|
||||
process: false
|
||||
|
||||
Reference in New Issue
Block a user