mirror of
https://github.com/tenrok/axios.git
synced 2026-06-23 20:40:40 +03:00
Merge remote-tracking branch 'refs/remotes/mzabriskie/master'
This commit is contained in:
@@ -9,6 +9,141 @@
|
|||||||
"node": true
|
"node": true
|
||||||
},
|
},
|
||||||
"rules": {
|
"rules": {
|
||||||
"quotes": [2, "single"]
|
/**
|
||||||
|
* Strict mode
|
||||||
|
*/
|
||||||
|
"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-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
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 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
|
||||||
|
}],
|
||||||
|
"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
|
||||||
|
],
|
||||||
|
"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-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
|
||||||
|
}],
|
||||||
|
"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
|
||||||
|
}],
|
||||||
|
"space-after-keywords": 2, // http://eslint.org/docs/rules/space-after-keywords
|
||||||
|
"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
|
||||||
|
"space-return-throw-case": 2, // http://eslint.org/docs/rules/space-return-throw-case
|
||||||
|
"spaced-comment": [2, "always", {// http://eslint.org/docs/rules/spaced-comment
|
||||||
|
"markers": ["global", "eslint"]
|
||||||
|
}]
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,7 +2,5 @@ language: node_js
|
|||||||
email:
|
email:
|
||||||
on_failure: change
|
on_failure: change
|
||||||
on_success: never
|
on_success: never
|
||||||
before_script:
|
|
||||||
- npm install -g grunt-cli
|
|
||||||
after_success:
|
after_success:
|
||||||
- npm run coveralls
|
- npm run coveralls
|
||||||
|
|||||||
+89
-71
@@ -1,73 +1,32 @@
|
|||||||
# Changelog
|
# Changelog
|
||||||
|
|
||||||
### 0.1.0 (Aug 29, 2014)
|
### 0.8.1 (Dec 14, 2015)
|
||||||
|
|
||||||
- Initial release
|
- Adding support for passing XSRF token for cross domain requests when using `withCredentials` ([#168](https://github.com/mzabriskie/axios/pull/168))
|
||||||
|
- Fixing error with format of basic auth header ([#178](https://github.com/mzabriskie/axios/pull/173))
|
||||||
|
- Fixing error with JSON payloads throwing `InvalidStateError` in some cases ([#174](https://github.com/mzabriskie/axios/pull/174))
|
||||||
|
|
||||||
### 0.2.0 (Sep 12, 2014)
|
### 0.8.0 (Dec 11, 2015)
|
||||||
|
|
||||||
- Adding support for `all` and `spread`
|
- Adding support for creating instances of axios ([#123](https://github.com/mzabriskie/axios/pull/123))
|
||||||
- Adding support for node.js ([#1](https://github.com/mzabriskie/axios/issues/1))
|
- Fixing http adapter to use `Buffer` instead of `String` in case of `responseType === 'arraybuffer'` ([#128](https://github.com/mzabriskie/axios/pull/128))
|
||||||
|
- Adding support for using custom parameter serializer with `paramsSerializer` option ([#121](https://github.com/mzabriskie/axios/pull/121))
|
||||||
|
- Fixing issue in IE8 caused by `forEach` on `arguments` ([#127](https://github.com/mzabriskie/axios/pull/127))
|
||||||
|
- Adding support for following redirects in node ([#146](https://github.com/mzabriskie/axios/pull/146))
|
||||||
|
- Adding support for transparent decompression if `content-encoding` is set ([#149](https://github.com/mzabriskie/axios/pull/149))
|
||||||
|
- Adding support for transparent XDomainRequest to handle cross domain requests in IE9 ([#140](https://github.com/mzabriskie/axios/pull/140))
|
||||||
|
- Adding support for HTTP basic auth via Authorization header ([#167](https://github.com/mzabriskie/axios/pull/167))
|
||||||
|
- Adding support for baseURL option ([#160](https://github.com/mzabriskie/axios/pull/160))
|
||||||
|
|
||||||
### 0.2.1 (Sep 12, 2014)
|
### 0.7.0 (Sep 29, 2015)
|
||||||
|
|
||||||
- Fixing build problem causing ridiculous file sizes
|
- Fixing issue with minified bundle in IE8 ([#87](https://github.com/mzabriskie/axios/pull/87))
|
||||||
|
- Adding support for passing agent in node ([#102](https://github.com/mzabriskie/axios/pull/102))
|
||||||
### 0.2.2 (Sep 14, 2014)
|
- Adding support for returning result from `axios.spread` for chaining ([#106](https://github.com/mzabriskie/axios/pull/106))
|
||||||
|
- Fixing typescript definition ([#105](https://github.com/mzabriskie/axios/pull/105))
|
||||||
- Fixing bundling with browserify ([#4](https://github.com/mzabriskie/axios/issues/4))
|
- Fixing default timeout config for node ([#112](https://github.com/mzabriskie/axios/pull/112))
|
||||||
|
- Adding support for use in web workers, and react-native ([#70](https://github.com/mzabriskie/axios/issue/70)), ([#98](https://github.com/mzabriskie/axios/pull/98))
|
||||||
### 0.3.0 (Sep 16, 2014)
|
- Adding support for fetch like API `axios(url[, config])` ([#116](https://github.com/mzabriskie/axios/issues/116))
|
||||||
|
|
||||||
- Fixing `success` and `error` to properly receive response data as individual arguments ([#8](https://github.com/mzabriskie/axios/issues/8))
|
|
||||||
- Updating `then` and `catch` to receive response data as a single object ([#6](https://github.com/mzabriskie/axios/issues/6))
|
|
||||||
- Fixing issue with `all` not working ([#7](https://github.com/mzabriskie/axios/issues/7))
|
|
||||||
|
|
||||||
### 0.3.1 (Sep 16, 2014)
|
|
||||||
|
|
||||||
- Fixing missing post body when using node.js ([#3](https://github.com/mzabriskie/axios/issues/3))
|
|
||||||
|
|
||||||
### 0.4.0 (Oct 03, 2014)
|
|
||||||
|
|
||||||
- Adding support for `ArrayBuffer` and `ArrayBufferView` ([#10](https://github.com/mzabriskie/axios/issues/10))
|
|
||||||
- Adding support for utf-8 for node.js ([#13](https://github.com/mzabriskie/axios/issues/13))
|
|
||||||
- Adding support for SSL for node.js ([#12](https://github.com/mzabriskie/axios/issues/12))
|
|
||||||
- Fixing incorrect `Content-Type` header ([#9](https://github.com/mzabriskie/axios/issues/9))
|
|
||||||
- Adding standalone build without bundled es6-promise ([#11](https://github.com/mzabriskie/axios/issues/11))
|
|
||||||
- Deprecating `success`/`error` in favor of `then`/`catch`
|
|
||||||
|
|
||||||
### 0.4.1 (Oct 15, 2014)
|
|
||||||
|
|
||||||
- Adding error handling to request for node.js ([#18](https://github.com/mzabriskie/axios/issues/18))
|
|
||||||
|
|
||||||
### 0.4.2 (Dec 10, 2014)
|
|
||||||
|
|
||||||
- Fixing issue with `Content-Type` when using `FormData` ([#22](https://github.com/mzabriskie/axios/issues/22))
|
|
||||||
- Adding support for TypeScript ([#25](https://github.com/mzabriskie/axios/issues/25))
|
|
||||||
- Fixing issue with standalone build ([#29](https://github.com/mzabriskie/axios/issues/29))
|
|
||||||
- Fixing issue with verbs needing to be capitalized in some browsers ([#30](https://github.com/mzabriskie/axios/issues/30))
|
|
||||||
|
|
||||||
### 0.5.0 (Jan 23, 2015)
|
|
||||||
|
|
||||||
- Adding support for intercepetors ([#14](https://github.com/mzabriskie/axios/issues/14))
|
|
||||||
- Updating es6-promise dependency
|
|
||||||
|
|
||||||
### 0.5.1 (Mar 10, 2015)
|
|
||||||
|
|
||||||
- Fixing issue using strict mode ([#45](https://github.com/mzabriskie/axios/issues/45))
|
|
||||||
- Fixing issue with standalone build ([#47](https://github.com/mzabriskie/axios/issues/47))
|
|
||||||
|
|
||||||
### 0.5.2 (Mar 13, 2015)
|
|
||||||
|
|
||||||
- Adding support for `statusText` in response ([#46](https://github.com/mzabriskie/axios/issues/46))
|
|
||||||
|
|
||||||
### 0.5.3 (Apr 07, 2015)
|
|
||||||
|
|
||||||
- Using JSON.parse unconditionally when transforming response string ([#55](https://github.com/mzabriskie/axios/issues/55))
|
|
||||||
|
|
||||||
### 0.5.4 (Apr 08, 2015)
|
|
||||||
|
|
||||||
- Fixing issue with FormData not being sent ([#53](https://github.com/mzabriskie/axios/issues/53))
|
|
||||||
|
|
||||||
### 0.6.0 (Sep 21, 2015)
|
### 0.6.0 (Sep 21, 2015)
|
||||||
|
|
||||||
@@ -80,12 +39,71 @@
|
|||||||
- Fixing issue with IE8 ([#85](https://github.com/mzabriskie/axios/pull/85))
|
- Fixing issue with IE8 ([#85](https://github.com/mzabriskie/axios/pull/85))
|
||||||
- Converting build to UMD
|
- Converting build to UMD
|
||||||
|
|
||||||
### 0.7.0 (Sep 29, 2015)
|
### 0.5.4 (Apr 08, 2015)
|
||||||
|
|
||||||
- Fixing issue with minified bundle in IE8 ([#87](https://github.com/mzabriskie/axios/pull/87))
|
- Fixing issue with FormData not being sent ([#53](https://github.com/mzabriskie/axios/issues/53))
|
||||||
- Adding support for passing agent in node ([#102](https://github.com/mzabriskie/axios/pull/102))
|
|
||||||
- Adding support for returning result from `axios.spread` for chaining ([#106](https://github.com/mzabriskie/axios/pull/106))
|
### 0.5.3 (Apr 07, 2015)
|
||||||
- Fixing typescript definition ([#105](https://github.com/mzabriskie/axios/pull/105))
|
|
||||||
- Fixing default timeout config for node ([#112](https://github.com/mzabriskie/axios/pull/112))
|
- Using JSON.parse unconditionally when transforming response string ([#55](https://github.com/mzabriskie/axios/issues/55))
|
||||||
- Adding support for use in web workers, and react-native ([#70](https://github.com/mzabriskie/axios/issue/70)), ([#98](https://github.com/mzabriskie/axios/pull/98))
|
|
||||||
- Adding support for fetch like API `axios(url[, config])` ([#116](https://github.com/mzabriskie/axios/issues/116))
|
### 0.5.2 (Mar 13, 2015)
|
||||||
|
|
||||||
|
- Adding support for `statusText` in response ([#46](https://github.com/mzabriskie/axios/issues/46))
|
||||||
|
|
||||||
|
### 0.5.1 (Mar 10, 2015)
|
||||||
|
|
||||||
|
- Fixing issue using strict mode ([#45](https://github.com/mzabriskie/axios/issues/45))
|
||||||
|
- Fixing issue with standalone build ([#47](https://github.com/mzabriskie/axios/issues/47))
|
||||||
|
|
||||||
|
### 0.5.0 (Jan 23, 2015)
|
||||||
|
|
||||||
|
- Adding support for intercepetors ([#14](https://github.com/mzabriskie/axios/issues/14))
|
||||||
|
- Updating es6-promise dependency
|
||||||
|
|
||||||
|
### 0.4.2 (Dec 10, 2014)
|
||||||
|
|
||||||
|
- Fixing issue with `Content-Type` when using `FormData` ([#22](https://github.com/mzabriskie/axios/issues/22))
|
||||||
|
- Adding support for TypeScript ([#25](https://github.com/mzabriskie/axios/issues/25))
|
||||||
|
- Fixing issue with standalone build ([#29](https://github.com/mzabriskie/axios/issues/29))
|
||||||
|
- Fixing issue with verbs needing to be capitalized in some browsers ([#30](https://github.com/mzabriskie/axios/issues/30))
|
||||||
|
|
||||||
|
### 0.4.1 (Oct 15, 2014)
|
||||||
|
|
||||||
|
- Adding error handling to request for node.js ([#18](https://github.com/mzabriskie/axios/issues/18))
|
||||||
|
|
||||||
|
### 0.4.0 (Oct 03, 2014)
|
||||||
|
|
||||||
|
- Adding support for `ArrayBuffer` and `ArrayBufferView` ([#10](https://github.com/mzabriskie/axios/issues/10))
|
||||||
|
- Adding support for utf-8 for node.js ([#13](https://github.com/mzabriskie/axios/issues/13))
|
||||||
|
- Adding support for SSL for node.js ([#12](https://github.com/mzabriskie/axios/issues/12))
|
||||||
|
- Fixing incorrect `Content-Type` header ([#9](https://github.com/mzabriskie/axios/issues/9))
|
||||||
|
- Adding standalone build without bundled es6-promise ([#11](https://github.com/mzabriskie/axios/issues/11))
|
||||||
|
- Deprecating `success`/`error` in favor of `then`/`catch`
|
||||||
|
|
||||||
|
### 0.3.1 (Sep 16, 2014)
|
||||||
|
|
||||||
|
- Fixing missing post body when using node.js ([#3](https://github.com/mzabriskie/axios/issues/3))
|
||||||
|
|
||||||
|
### 0.3.0 (Sep 16, 2014)
|
||||||
|
|
||||||
|
- Fixing `success` and `error` to properly receive response data as individual arguments ([#8](https://github.com/mzabriskie/axios/issues/8))
|
||||||
|
- Updating `then` and `catch` to receive response data as a single object ([#6](https://github.com/mzabriskie/axios/issues/6))
|
||||||
|
- Fixing issue with `all` not working ([#7](https://github.com/mzabriskie/axios/issues/7))
|
||||||
|
|
||||||
|
### 0.2.2 (Sep 14, 2014)
|
||||||
|
|
||||||
|
- Fixing bundling with browserify ([#4](https://github.com/mzabriskie/axios/issues/4))
|
||||||
|
|
||||||
|
### 0.2.1 (Sep 12, 2014)
|
||||||
|
|
||||||
|
- Fixing build problem causing ridiculous file sizes
|
||||||
|
|
||||||
|
### 0.2.0 (Sep 12, 2014)
|
||||||
|
|
||||||
|
- Adding support for `all` and `spread`
|
||||||
|
- Adding support for node.js ([#1](https://github.com/mzabriskie/axios/issues/1))
|
||||||
|
|
||||||
|
### 0.1.0 (Aug 29, 2014)
|
||||||
|
|
||||||
|
- Initial release
|
||||||
|
|||||||
@@ -132,15 +132,46 @@ Helper functions for dealing with concurrent requests.
|
|||||||
##### axios.all(iterable)
|
##### axios.all(iterable)
|
||||||
##### axios.spread(callback)
|
##### axios.spread(callback)
|
||||||
|
|
||||||
|
### Creating an instance
|
||||||
|
|
||||||
|
You can create a new instance of axios with a custom config.
|
||||||
|
|
||||||
|
##### axios.create([config])
|
||||||
|
|
||||||
|
```js
|
||||||
|
var instance = axios.create({
|
||||||
|
baseURL: 'https://some-domain.com/api/',
|
||||||
|
timeout: 1000,
|
||||||
|
headers: {'X-Custom-Header': 'foobar'}
|
||||||
|
});
|
||||||
|
```
|
||||||
|
|
||||||
|
### Instance methods
|
||||||
|
|
||||||
|
The available instance methods are listed below. The specified config will be merged with the instance config.
|
||||||
|
|
||||||
|
##### axios#request(config)
|
||||||
|
##### axios#get(url[, config])
|
||||||
|
##### axios#delete(url[, config])
|
||||||
|
##### axios#head(url[, config])
|
||||||
|
##### axios#post(url[, data[, config]])
|
||||||
|
##### axios#put(url[, data[, config]])
|
||||||
|
##### axios#patch(url[, data[, config]])
|
||||||
|
|
||||||
## Request API
|
## Request API
|
||||||
|
|
||||||
This is the available config options for making requests. Only the `url` is required. Requests will default to `GET` if `method` is not specified.
|
These are the available config options for making requests. Only the `url` is required. Requests will default to `GET` if `method` is not specified.
|
||||||
|
|
||||||
```js
|
```js
|
||||||
{
|
{
|
||||||
// `url` is the server URL that will be used for the request
|
// `url` is the server URL that will be used for the request
|
||||||
url: '/user',
|
url: '/user',
|
||||||
|
|
||||||
|
// `baseURL` will be prepended to `url` unless `url` is absolute.
|
||||||
|
// It can be convenient to set `baseURL` for an instance of axios to pass relative URLs
|
||||||
|
// to methods of that instance.
|
||||||
|
baseURL: 'https://some-domain.com/api/',
|
||||||
|
|
||||||
// `method` is the request method to be used when making the request
|
// `method` is the request method to be used when making the request
|
||||||
method: 'get', // default
|
method: 'get', // default
|
||||||
|
|
||||||
@@ -169,6 +200,12 @@ This is the available config options for making requests. Only the `url` is requ
|
|||||||
ID: 12345
|
ID: 12345
|
||||||
},
|
},
|
||||||
|
|
||||||
|
// `paramsSerializer` is an optional function in charge of serializing `params`
|
||||||
|
// (e.g. https://www.npmjs.com/package/qs, http://api.jquery.com/jquery.param/)
|
||||||
|
paramsSerializer: function(params) {
|
||||||
|
return Qs.stringify(params, {arrayFormat: 'brackets'})
|
||||||
|
},
|
||||||
|
|
||||||
// `data` is the data to be sent as the request body
|
// `data` is the data to be sent as the request body
|
||||||
// Only applicable for request methods 'PUT', 'POST', and 'PATCH'
|
// Only applicable for request methods 'PUT', 'POST', and 'PATCH'
|
||||||
// When no `transformRequest` is set, must be a string, an ArrayBuffer or a hash
|
// When no `transformRequest` is set, must be a string, an ArrayBuffer or a hash
|
||||||
@@ -184,6 +221,14 @@ This is the available config options for making requests. Only the `url` is requ
|
|||||||
// should be made using credentials
|
// should be made using credentials
|
||||||
withCredentials: false, // default
|
withCredentials: false, // default
|
||||||
|
|
||||||
|
// `auth` indicates that HTTP Basic auth should be used, and supplies credentials.
|
||||||
|
// This will set an `Authorization` header, overwriting any existing
|
||||||
|
// `Authorization` custom headers you have set using `headers`.
|
||||||
|
auth: {
|
||||||
|
username: 'janedoe',
|
||||||
|
password: 's00pers3cret'
|
||||||
|
}
|
||||||
|
|
||||||
// `responseType` indicates the type of data that the server will respond with
|
// `responseType` indicates the type of data that the server will respond with
|
||||||
// options are 'arraybuffer', 'blob', 'document', 'json', 'text'
|
// options are 'arraybuffer', 'blob', 'document', 'json', 'text'
|
||||||
responseType: 'json', // default
|
responseType: 'json', // default
|
||||||
@@ -263,6 +308,13 @@ var myInterceptor = axios.interceptors.request.use(function () {/*...*/});
|
|||||||
axios.interceptors.request.eject(myInterceptor);
|
axios.interceptors.request.eject(myInterceptor);
|
||||||
```
|
```
|
||||||
|
|
||||||
|
You can add interceptors to a custom instance of axios.
|
||||||
|
|
||||||
|
```js
|
||||||
|
var instance = axios.create();
|
||||||
|
instance.interceptors.request.use(function () {/*...*/});
|
||||||
|
```
|
||||||
|
|
||||||
## Handling Errors
|
## Handling Errors
|
||||||
|
|
||||||
```js
|
```js
|
||||||
|
|||||||
Vendored
+23
-8
@@ -1,4 +1,4 @@
|
|||||||
// Type definitions for Axios v0.7.0
|
// Type definitions for Axios v0.8.1
|
||||||
// Project: https://github.com/mzabriskie/axios
|
// Project: https://github.com/mzabriskie/axios
|
||||||
|
|
||||||
|
|
||||||
@@ -6,18 +6,26 @@
|
|||||||
declare var axios: axios.AxiosStatic
|
declare var axios: axios.AxiosStatic
|
||||||
|
|
||||||
declare module axios {
|
declare module axios {
|
||||||
interface AxiosStatic {
|
interface AxiosRequestMethods {
|
||||||
(options: axios.RequestOptions): axios.Promise;
|
|
||||||
get(url: string, config?: any): axios.Promise;
|
get(url: string, config?: any): axios.Promise;
|
||||||
delete(url: string, config?: any): axios.Promise;
|
delete(url: string, config?: any): axios.Promise;
|
||||||
head(url: string, config?: any): axios.Promise;
|
head(url: string, config?: any): axios.Promise;
|
||||||
post(url: string, data: any, config?: any): axios.Promise;
|
post(url: string, data: any, config?: any): axios.Promise;
|
||||||
put(url: string, data: any, config?: any): axios.Promise;
|
put(url: string, data: any, config?: any): axios.Promise;
|
||||||
patch(url: string, data: any, config?: any): axios.Promise;
|
patch(url: string, data: any, config?: any): axios.Promise;
|
||||||
|
}
|
||||||
|
|
||||||
|
interface AxiosStatic extends AxiosRequestMethods {
|
||||||
|
(options: axios.RequestOptions): axios.Promise;
|
||||||
|
create(defaultOptions?: axios.InstanceOptions): AxiosInstance;
|
||||||
all(iterable: any): axios.Promise;
|
all(iterable: any): axios.Promise;
|
||||||
spread(callback: any): axios.Promise;
|
spread(callback: any): axios.Promise;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
interface AxiosInstance extends AxiosRequestMethods {
|
||||||
|
request(options: axios.RequestOptions): axios.Promise;
|
||||||
|
}
|
||||||
|
|
||||||
interface Response {
|
interface Response {
|
||||||
data?: any;
|
data?: any;
|
||||||
status?: number;
|
status?: number;
|
||||||
@@ -31,17 +39,24 @@ declare module axios {
|
|||||||
catch(onRejected:(response: axios.Response) => void): axios.Promise;
|
catch(onRejected:(response: axios.Response) => void): axios.Promise;
|
||||||
}
|
}
|
||||||
|
|
||||||
interface RequestOptions {
|
interface InstanceOptions {
|
||||||
url: string;
|
|
||||||
method?: string;
|
|
||||||
transformRequest?: (data: any) => any;
|
transformRequest?: (data: any) => any;
|
||||||
|
transformResponse?: (data: any) => any;
|
||||||
headers?: any;
|
headers?: any;
|
||||||
params?: any;
|
timeout?: number;
|
||||||
data?: any;
|
|
||||||
withCredentials?: boolean;
|
withCredentials?: boolean;
|
||||||
responseType?: string;
|
responseType?: string;
|
||||||
xsrfCookieName?: string;
|
xsrfCookieName?: string;
|
||||||
xsrfHeaderName?: string;
|
xsrfHeaderName?: string;
|
||||||
|
paramsSerializer?: (params: any) => string;
|
||||||
|
baseURL?: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
interface RequestOptions extends InstanceOptions {
|
||||||
|
url: string;
|
||||||
|
method?: string;
|
||||||
|
params?: any;
|
||||||
|
data?: any;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+1
-1
@@ -1,7 +1,7 @@
|
|||||||
{
|
{
|
||||||
"name": "axios",
|
"name": "axios",
|
||||||
"main": "./dist/axios.js",
|
"main": "./dist/axios.js",
|
||||||
"version": "0.7.0",
|
"version": "0.8.1",
|
||||||
"homepage": "https://github.com/mzabriskie/axios",
|
"homepage": "https://github.com/mzabriskie/axios",
|
||||||
"authors": [
|
"authors": [
|
||||||
"Matt Zabriskie"
|
"Matt Zabriskie"
|
||||||
|
|||||||
Vendored
+382
-325
@@ -1,4 +1,4 @@
|
|||||||
/* axios v0.7.0 | (c) 2015 by Matt Zabriskie */
|
/* axios v0.8.0 | (c) 2015 by Matt Zabriskie */
|
||||||
(function webpackUniversalModuleDefinition(root, factory) {
|
(function webpackUniversalModuleDefinition(root, factory) {
|
||||||
if(typeof exports === 'object' && typeof module === 'object')
|
if(typeof exports === 'object' && typeof module === 'object')
|
||||||
module.exports = factory();
|
module.exports = factory();
|
||||||
@@ -67,8 +67,26 @@ return /******/ (function(modules) { // webpackBootstrap
|
|||||||
var utils = __webpack_require__(3);
|
var utils = __webpack_require__(3);
|
||||||
var dispatchRequest = __webpack_require__(4);
|
var dispatchRequest = __webpack_require__(4);
|
||||||
var InterceptorManager = __webpack_require__(12);
|
var InterceptorManager = __webpack_require__(12);
|
||||||
|
var isAbsoluteURL = __webpack_require__(13);
|
||||||
|
var combineURLs = __webpack_require__(14);
|
||||||
|
var bind = __webpack_require__(15);
|
||||||
|
|
||||||
var axios = module.exports = function (config) {
|
function Axios(defaultConfig) {
|
||||||
|
this.defaultConfig = utils.merge({
|
||||||
|
headers: {},
|
||||||
|
timeout: defaults.timeout,
|
||||||
|
transformRequest: defaults.transformRequest,
|
||||||
|
transformResponse: defaults.transformResponse
|
||||||
|
}, defaultConfig);
|
||||||
|
|
||||||
|
this.interceptors = {
|
||||||
|
request: new InterceptorManager(),
|
||||||
|
response: new InterceptorManager()
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
Axios.prototype.request = function request(config) {
|
||||||
|
/*eslint no-param-reassign:0*/
|
||||||
// Allow for axios('example/url'[, config]) a la fetch API
|
// Allow for axios('example/url'[, config]) a la fetch API
|
||||||
if (typeof config === 'string') {
|
if (typeof config === 'string') {
|
||||||
config = utils.merge({
|
config = utils.merge({
|
||||||
@@ -76,13 +94,11 @@ return /******/ (function(modules) { // webpackBootstrap
|
|||||||
}, arguments[1]);
|
}, arguments[1]);
|
||||||
}
|
}
|
||||||
|
|
||||||
config = utils.merge({
|
config = utils.merge(this.defaultConfig, { method: 'get' }, config);
|
||||||
method: 'get',
|
|
||||||
headers: {},
|
if (config.baseURL && !isAbsoluteURL(config.url)) {
|
||||||
timeout: defaults.timeout,
|
config.url = combineURLs(config.baseURL, config.url);
|
||||||
transformRequest: defaults.transformRequest,
|
}
|
||||||
transformResponse: defaults.transformResponse
|
|
||||||
}, config);
|
|
||||||
|
|
||||||
// Don't allow overriding defaults.withCredentials
|
// Don't allow overriding defaults.withCredentials
|
||||||
config.withCredentials = config.withCredentials || defaults.withCredentials;
|
config.withCredentials = config.withCredentials || defaults.withCredentials;
|
||||||
@@ -91,11 +107,11 @@ return /******/ (function(modules) { // webpackBootstrap
|
|||||||
var chain = [dispatchRequest, undefined];
|
var chain = [dispatchRequest, undefined];
|
||||||
var promise = Promise.resolve(config);
|
var promise = Promise.resolve(config);
|
||||||
|
|
||||||
axios.interceptors.request.forEach(function (interceptor) {
|
this.interceptors.request.forEach(function unshiftRequestInterceptors(interceptor) {
|
||||||
chain.unshift(interceptor.fulfilled, interceptor.rejected);
|
chain.unshift(interceptor.fulfilled, interceptor.rejected);
|
||||||
});
|
});
|
||||||
|
|
||||||
axios.interceptors.response.forEach(function (interceptor) {
|
this.interceptors.response.forEach(function pushResponseInterceptors(interceptor) {
|
||||||
chain.push(interceptor.fulfilled, interceptor.rejected);
|
chain.push(interceptor.fulfilled, interceptor.rejected);
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -106,49 +122,49 @@ return /******/ (function(modules) { // webpackBootstrap
|
|||||||
return promise;
|
return promise;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
var defaultInstance = new Axios();
|
||||||
|
|
||||||
|
var axios = module.exports = bind(Axios.prototype.request, defaultInstance);
|
||||||
|
|
||||||
|
axios.create = function create(defaultConfig) {
|
||||||
|
return new Axios(defaultConfig);
|
||||||
|
};
|
||||||
|
|
||||||
// Expose defaults
|
// Expose defaults
|
||||||
axios.defaults = defaults;
|
axios.defaults = defaults;
|
||||||
|
|
||||||
// Expose all/spread
|
// Expose all/spread
|
||||||
axios.all = function (promises) {
|
axios.all = function all(promises) {
|
||||||
return Promise.all(promises);
|
return Promise.all(promises);
|
||||||
};
|
};
|
||||||
axios.spread = __webpack_require__(13);
|
axios.spread = __webpack_require__(16);
|
||||||
|
|
||||||
// Expose interceptors
|
// Expose interceptors
|
||||||
axios.interceptors = {
|
axios.interceptors = defaultInstance.interceptors;
|
||||||
request: new InterceptorManager(),
|
|
||||||
response: new InterceptorManager()
|
|
||||||
};
|
|
||||||
|
|
||||||
// Provide aliases for supported request methods
|
// Provide aliases for supported request methods
|
||||||
(function () {
|
utils.forEach(['delete', 'get', 'head'], function forEachMethodNoData(method) {
|
||||||
function createShortMethods() {
|
/*eslint func-names:0*/
|
||||||
utils.forEach(arguments, function (method) {
|
Axios.prototype[method] = function(url, config) {
|
||||||
axios[method] = function (url, config) {
|
return this.request(utils.merge(config || {}, {
|
||||||
return axios(utils.merge(config || {}, {
|
method: method,
|
||||||
method: method,
|
url: url
|
||||||
url: url
|
}));
|
||||||
}));
|
};
|
||||||
};
|
axios[method] = bind(Axios.prototype[method], defaultInstance);
|
||||||
});
|
});
|
||||||
}
|
|
||||||
|
|
||||||
function createShortMethodsWithData() {
|
utils.forEach(['post', 'put', 'patch'], function forEachMethodWithData(method) {
|
||||||
utils.forEach(arguments, function (method) {
|
/*eslint func-names:0*/
|
||||||
axios[method] = function (url, data, config) {
|
Axios.prototype[method] = function(url, data, config) {
|
||||||
return axios(utils.merge(config || {}, {
|
return this.request(utils.merge(config || {}, {
|
||||||
method: method,
|
method: method,
|
||||||
url: url,
|
url: url,
|
||||||
data: data
|
data: data
|
||||||
}));
|
}));
|
||||||
};
|
};
|
||||||
});
|
axios[method] = bind(Axios.prototype[method], defaultInstance);
|
||||||
}
|
});
|
||||||
|
|
||||||
createShortMethods('delete', 'get', 'head');
|
|
||||||
createShortMethodsWithData('post', 'put', 'patch');
|
|
||||||
})();
|
|
||||||
|
|
||||||
|
|
||||||
/***/ },
|
/***/ },
|
||||||
@@ -165,8 +181,8 @@ return /******/ (function(modules) { // webpackBootstrap
|
|||||||
};
|
};
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
transformRequest: [function (data, headers) {
|
transformRequest: [function transformResponseJSON(data, headers) {
|
||||||
if(utils.isFormData(data)) {
|
if (utils.isFormData(data)) {
|
||||||
return data;
|
return data;
|
||||||
}
|
}
|
||||||
if (utils.isArrayBuffer(data)) {
|
if (utils.isArrayBuffer(data)) {
|
||||||
@@ -178,7 +194,7 @@ return /******/ (function(modules) { // webpackBootstrap
|
|||||||
if (utils.isObject(data) && !utils.isFile(data) && !utils.isBlob(data)) {
|
if (utils.isObject(data) && !utils.isFile(data) && !utils.isBlob(data)) {
|
||||||
// Set application/json if no Content-Type has been specified
|
// Set application/json if no Content-Type has been specified
|
||||||
if (!utils.isUndefined(headers)) {
|
if (!utils.isUndefined(headers)) {
|
||||||
utils.forEach(headers, function (val, key) {
|
utils.forEach(headers, function processContentTypeHeader(val, key) {
|
||||||
if (key.toLowerCase() === 'content-type') {
|
if (key.toLowerCase() === 'content-type') {
|
||||||
headers['Content-Type'] = val;
|
headers['Content-Type'] = val;
|
||||||
}
|
}
|
||||||
@@ -193,7 +209,8 @@ return /******/ (function(modules) { // webpackBootstrap
|
|||||||
return data;
|
return data;
|
||||||
}],
|
}],
|
||||||
|
|
||||||
transformResponse: [function (data) {
|
transformResponse: [function transformResponseJSON(data) {
|
||||||
|
/*eslint no-param-reassign:0*/
|
||||||
if (typeof data === 'string') {
|
if (typeof data === 'string') {
|
||||||
data = data.replace(PROTECTION_PREFIX, '');
|
data = data.replace(PROTECTION_PREFIX, '');
|
||||||
try {
|
try {
|
||||||
@@ -268,11 +285,13 @@ return /******/ (function(modules) { // webpackBootstrap
|
|||||||
* @returns {boolean} True if value is a view on an ArrayBuffer, otherwise false
|
* @returns {boolean} True if value is a view on an ArrayBuffer, otherwise false
|
||||||
*/
|
*/
|
||||||
function isArrayBufferView(val) {
|
function isArrayBufferView(val) {
|
||||||
|
var result;
|
||||||
if ((typeof ArrayBuffer !== 'undefined') && (ArrayBuffer.isView)) {
|
if ((typeof ArrayBuffer !== 'undefined') && (ArrayBuffer.isView)) {
|
||||||
return ArrayBuffer.isView(val);
|
result = ArrayBuffer.isView(val);
|
||||||
} else {
|
} else {
|
||||||
return (val) && (val.buffer) && (val.buffer instanceof ArrayBuffer);
|
result = (val) && (val.buffer) && (val.buffer instanceof ArrayBuffer);
|
||||||
}
|
}
|
||||||
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -355,16 +374,6 @@ return /******/ (function(modules) { // webpackBootstrap
|
|||||||
return str.replace(/^\s*/, '').replace(/\s*$/, '');
|
return str.replace(/^\s*/, '').replace(/\s*$/, '');
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Determine if a value is an Arguments object
|
|
||||||
*
|
|
||||||
* @param {Object} val The value to test
|
|
||||||
* @returns {boolean} True if value is an Arguments object, otherwise false
|
|
||||||
*/
|
|
||||||
function isArguments(val) {
|
|
||||||
return toString.call(val) === '[object Arguments]';
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Determine if we're running in a standard browser environment
|
* Determine if we're running in a standard browser environment
|
||||||
*
|
*
|
||||||
@@ -376,7 +385,7 @@ return /******/ (function(modules) { // webpackBootstrap
|
|||||||
* typeof document -> undefined
|
* typeof document -> undefined
|
||||||
*
|
*
|
||||||
* react-native:
|
* react-native:
|
||||||
* typeof document.createelement -> undefined
|
* typeof document.createElement -> undefined
|
||||||
*/
|
*/
|
||||||
function isStandardBrowserEnv() {
|
function isStandardBrowserEnv() {
|
||||||
return (
|
return (
|
||||||
@@ -389,7 +398,7 @@ return /******/ (function(modules) { // webpackBootstrap
|
|||||||
/**
|
/**
|
||||||
* Iterate over an Array or an Object invoking a function for each item.
|
* Iterate over an Array or an Object invoking a function for each item.
|
||||||
*
|
*
|
||||||
* If `obj` is an Array or arguments callback will be called passing
|
* If `obj` is an Array callback will be called passing
|
||||||
* the value, index, and complete array for each item.
|
* the value, index, and complete array for each item.
|
||||||
*
|
*
|
||||||
* If 'obj' is an Object callback will be called passing
|
* If 'obj' is an Object callback will be called passing
|
||||||
@@ -404,22 +413,19 @@ return /******/ (function(modules) { // webpackBootstrap
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check if obj is array-like
|
|
||||||
var isArrayLike = isArray(obj) || isArguments(obj);
|
|
||||||
|
|
||||||
// Force an array if not already something iterable
|
// Force an array if not already something iterable
|
||||||
if (typeof obj !== 'object' && !isArrayLike) {
|
if (typeof obj !== 'object' && !isArray(obj)) {
|
||||||
|
/*eslint no-param-reassign:0*/
|
||||||
obj = [obj];
|
obj = [obj];
|
||||||
}
|
}
|
||||||
|
|
||||||
// Iterate over array values
|
if (isArray(obj)) {
|
||||||
if (isArrayLike) {
|
// Iterate over array values
|
||||||
for (var i = 0, l = obj.length; i < l; i++) {
|
for (var i = 0, l = obj.length; i < l; i++) {
|
||||||
fn.call(null, obj[i], i, obj);
|
fn.call(null, obj[i], i, obj);
|
||||||
}
|
}
|
||||||
}
|
} else {
|
||||||
// Iterate over object keys
|
// Iterate over object keys
|
||||||
else {
|
|
||||||
for (var key in obj) {
|
for (var key in obj) {
|
||||||
if (obj.hasOwnProperty(key)) {
|
if (obj.hasOwnProperty(key)) {
|
||||||
fn.call(null, obj[key], key, obj);
|
fn.call(null, obj[key], key, obj);
|
||||||
@@ -445,13 +451,15 @@ return /******/ (function(modules) { // webpackBootstrap
|
|||||||
* @param {Object} obj1 Object to merge
|
* @param {Object} obj1 Object to merge
|
||||||
* @returns {Object} Result of all merge properties
|
* @returns {Object} Result of all merge properties
|
||||||
*/
|
*/
|
||||||
function merge(/*obj1, obj2, obj3, ...*/) {
|
function merge(/* obj1, obj2, obj3, ... */) {
|
||||||
var result = {};
|
var result = {};
|
||||||
forEach(arguments, function (obj) {
|
function assignValue(val, key) {
|
||||||
forEach(obj, function (val, key) {
|
result[key] = val;
|
||||||
result[key] = val;
|
}
|
||||||
});
|
|
||||||
});
|
for (var i = 0, l = arguments.length; i < l; i++) {
|
||||||
|
forEach(arguments[i], assignValue);
|
||||||
|
}
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -478,7 +486,7 @@ return /******/ (function(modules) { // webpackBootstrap
|
|||||||
/* 4 */
|
/* 4 */
|
||||||
/***/ function(module, exports, __webpack_require__) {
|
/***/ function(module, exports, __webpack_require__) {
|
||||||
|
|
||||||
/* WEBPACK VAR INJECTION */(function(process) {'use strict';
|
'use strict';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Dispatch a request to the server using whichever adapter
|
* Dispatch a request to the server using whichever adapter
|
||||||
@@ -488,15 +496,14 @@ return /******/ (function(modules) { // webpackBootstrap
|
|||||||
* @returns {Promise} The Promise to be fulfilled
|
* @returns {Promise} The Promise to be fulfilled
|
||||||
*/
|
*/
|
||||||
module.exports = function dispatchRequest(config) {
|
module.exports = function dispatchRequest(config) {
|
||||||
return new Promise(function (resolve, reject) {
|
return new Promise(function executor(resolve, reject) {
|
||||||
try {
|
try {
|
||||||
// For browsers use XHR adapter
|
|
||||||
if ((typeof XMLHttpRequest !== 'undefined') || (typeof ActiveXObject !== 'undefined')) {
|
if ((typeof XMLHttpRequest !== 'undefined') || (typeof ActiveXObject !== 'undefined')) {
|
||||||
__webpack_require__(6)(resolve, reject, config);
|
// For browsers use XHR adapter
|
||||||
}
|
__webpack_require__(5)(resolve, reject, config);
|
||||||
// For node use HTTP adapter
|
} else if (typeof process !== 'undefined') {
|
||||||
else if (typeof process !== 'undefined') {
|
// For node use HTTP adapter
|
||||||
__webpack_require__(6)(resolve, reject, config);
|
__webpack_require__(5)(resolve, reject, config);
|
||||||
}
|
}
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
reject(e);
|
reject(e);
|
||||||
@@ -505,107 +512,9 @@ return /******/ (function(modules) { // webpackBootstrap
|
|||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
/* WEBPACK VAR INJECTION */}.call(exports, __webpack_require__(5)))
|
|
||||||
|
|
||||||
/***/ },
|
/***/ },
|
||||||
/* 5 */
|
/* 5 */
|
||||||
/***/ function(module, exports) {
|
|
||||||
|
|
||||||
// shim for using process in browser
|
|
||||||
|
|
||||||
var process = module.exports = {};
|
|
||||||
var queue = [];
|
|
||||||
var draining = false;
|
|
||||||
var currentQueue;
|
|
||||||
var queueIndex = -1;
|
|
||||||
|
|
||||||
function cleanUpNextTick() {
|
|
||||||
draining = false;
|
|
||||||
if (currentQueue.length) {
|
|
||||||
queue = currentQueue.concat(queue);
|
|
||||||
} else {
|
|
||||||
queueIndex = -1;
|
|
||||||
}
|
|
||||||
if (queue.length) {
|
|
||||||
drainQueue();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
function drainQueue() {
|
|
||||||
if (draining) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
var timeout = setTimeout(cleanUpNextTick);
|
|
||||||
draining = true;
|
|
||||||
|
|
||||||
var len = queue.length;
|
|
||||||
while(len) {
|
|
||||||
currentQueue = queue;
|
|
||||||
queue = [];
|
|
||||||
while (++queueIndex < len) {
|
|
||||||
if (currentQueue) {
|
|
||||||
currentQueue[queueIndex].run();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
queueIndex = -1;
|
|
||||||
len = queue.length;
|
|
||||||
}
|
|
||||||
currentQueue = null;
|
|
||||||
draining = false;
|
|
||||||
clearTimeout(timeout);
|
|
||||||
}
|
|
||||||
|
|
||||||
process.nextTick = function (fun) {
|
|
||||||
var args = new Array(arguments.length - 1);
|
|
||||||
if (arguments.length > 1) {
|
|
||||||
for (var i = 1; i < arguments.length; i++) {
|
|
||||||
args[i - 1] = arguments[i];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
queue.push(new Item(fun, args));
|
|
||||||
if (queue.length === 1 && !draining) {
|
|
||||||
setTimeout(drainQueue, 0);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
// v8 likes predictible objects
|
|
||||||
function Item(fun, array) {
|
|
||||||
this.fun = fun;
|
|
||||||
this.array = array;
|
|
||||||
}
|
|
||||||
Item.prototype.run = function () {
|
|
||||||
this.fun.apply(null, this.array);
|
|
||||||
};
|
|
||||||
process.title = 'browser';
|
|
||||||
process.browser = true;
|
|
||||||
process.env = {};
|
|
||||||
process.argv = [];
|
|
||||||
process.version = ''; // empty string to avoid regexp issues
|
|
||||||
process.versions = {};
|
|
||||||
|
|
||||||
function noop() {}
|
|
||||||
|
|
||||||
process.on = noop;
|
|
||||||
process.addListener = noop;
|
|
||||||
process.once = noop;
|
|
||||||
process.off = noop;
|
|
||||||
process.removeListener = noop;
|
|
||||||
process.removeAllListeners = noop;
|
|
||||||
process.emit = noop;
|
|
||||||
|
|
||||||
process.binding = function (name) {
|
|
||||||
throw new Error('process.binding is not supported');
|
|
||||||
};
|
|
||||||
|
|
||||||
process.cwd = function () { return '/' };
|
|
||||||
process.chdir = function (dir) {
|
|
||||||
throw new Error('process.chdir is not supported');
|
|
||||||
};
|
|
||||||
process.umask = function() { return 0; };
|
|
||||||
|
|
||||||
|
|
||||||
/***/ },
|
|
||||||
/* 6 */
|
|
||||||
/***/ function(module, exports, __webpack_require__) {
|
/***/ function(module, exports, __webpack_require__) {
|
||||||
|
|
||||||
'use strict';
|
'use strict';
|
||||||
@@ -614,9 +523,11 @@ return /******/ (function(modules) { // webpackBootstrap
|
|||||||
|
|
||||||
var defaults = __webpack_require__(2);
|
var defaults = __webpack_require__(2);
|
||||||
var utils = __webpack_require__(3);
|
var utils = __webpack_require__(3);
|
||||||
var buildUrl = __webpack_require__(7);
|
var buildURL = __webpack_require__(6);
|
||||||
var parseHeaders = __webpack_require__(8);
|
var parseHeaders = __webpack_require__(7);
|
||||||
var transformData = __webpack_require__(9);
|
var transformData = __webpack_require__(8);
|
||||||
|
var isURLSameOrigin = __webpack_require__(9);
|
||||||
|
var btoa = window.btoa || __webpack_require__(10);
|
||||||
|
|
||||||
module.exports = function xhrAdapter(resolve, reject, config) {
|
module.exports = function xhrAdapter(resolve, reject, config) {
|
||||||
// Transform request data
|
// Transform request data
|
||||||
@@ -637,18 +548,36 @@ return /******/ (function(modules) { // webpackBootstrap
|
|||||||
delete requestHeaders['Content-Type']; // Let the browser set it
|
delete requestHeaders['Content-Type']; // Let the browser set it
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var Adapter = (XMLHttpRequest || ActiveXObject);
|
||||||
|
var loadEvent = 'onreadystatechange';
|
||||||
|
var xDomain = false;
|
||||||
|
|
||||||
|
// For IE 8/9 CORS support
|
||||||
|
if (!isURLSameOrigin(config.url) && window.XDomainRequest) {
|
||||||
|
Adapter = window.XDomainRequest;
|
||||||
|
loadEvent = 'onload';
|
||||||
|
xDomain = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
// HTTP basic authentication
|
||||||
|
if (config.auth) {
|
||||||
|
var username = config.auth.username || '';
|
||||||
|
var password = config.auth.password || '';
|
||||||
|
requestHeaders.Authorization = 'Basic ' + btoa(username + ':' + password);
|
||||||
|
}
|
||||||
|
|
||||||
// Create the request
|
// Create the request
|
||||||
var request = new (XMLHttpRequest || ActiveXObject)('Microsoft.XMLHTTP');
|
var request = new Adapter('Microsoft.XMLHTTP');
|
||||||
request.open(config.method.toUpperCase(), buildUrl(config.url, config.params), true);
|
request.open(config.method.toUpperCase(), buildURL(config.url, config.params, config.paramsSerializer), true);
|
||||||
|
|
||||||
// Set the request timeout in MS
|
// Set the request timeout in MS
|
||||||
request.timeout = config.timeout;
|
request.timeout = config.timeout;
|
||||||
|
|
||||||
// Listen for ready state
|
// Listen for ready state
|
||||||
request.onreadystatechange = function () {
|
request[loadEvent] = function handleReadyState() {
|
||||||
if (request && request.readyState === 4) {
|
if (request && (request.readyState === 4 || xDomain)) {
|
||||||
// Prepare the response
|
// Prepare the response
|
||||||
var responseHeaders = parseHeaders(request.getAllResponseHeaders());
|
var responseHeaders = xDomain ? null : parseHeaders(request.getAllResponseHeaders());
|
||||||
var responseData = ['text', ''].indexOf(config.responseType || '') !== -1 ? request.responseText : request.response;
|
var responseData = ['text', ''].indexOf(config.responseType || '') !== -1 ? request.responseText : request.response;
|
||||||
var response = {
|
var response = {
|
||||||
data: transformData(
|
data: transformData(
|
||||||
@@ -661,9 +590,8 @@ return /******/ (function(modules) { // webpackBootstrap
|
|||||||
headers: responseHeaders,
|
headers: responseHeaders,
|
||||||
config: config
|
config: config
|
||||||
};
|
};
|
||||||
|
|
||||||
// Resolve or reject the Promise based on the status
|
// Resolve or reject the Promise based on the status
|
||||||
(request.status >= 200 && request.status < 300 ?
|
((request.status >= 200 && request.status < 300) || (xDomain && request.responseText) ?
|
||||||
resolve :
|
resolve :
|
||||||
reject)(response);
|
reject)(response);
|
||||||
|
|
||||||
@@ -676,11 +604,10 @@ return /******/ (function(modules) { // webpackBootstrap
|
|||||||
// This is only done if running in a standard browser environment.
|
// This is only done if running in a standard browser environment.
|
||||||
// Specifically not if we're in a web worker, or react-native.
|
// Specifically not if we're in a web worker, or react-native.
|
||||||
if (utils.isStandardBrowserEnv()) {
|
if (utils.isStandardBrowserEnv()) {
|
||||||
var cookies = __webpack_require__(10);
|
var cookies = __webpack_require__(11);
|
||||||
var urlIsSameOrigin = __webpack_require__(11);
|
|
||||||
|
|
||||||
// Add xsrf header
|
// Add xsrf header
|
||||||
var xsrfValue = urlIsSameOrigin(config.url) ?
|
var xsrfValue = config.withCredentials || isURLSameOrigin(config.url) ?
|
||||||
cookies.read(config.xsrfCookieName || defaults.xsrfCookieName) :
|
cookies.read(config.xsrfCookieName || defaults.xsrfCookieName) :
|
||||||
undefined;
|
undefined;
|
||||||
|
|
||||||
@@ -690,16 +617,17 @@ return /******/ (function(modules) { // webpackBootstrap
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Add headers to the request
|
// Add headers to the request
|
||||||
utils.forEach(requestHeaders, function (val, key) {
|
if (!xDomain) {
|
||||||
// Remove Content-Type if data is undefined
|
utils.forEach(requestHeaders, function setRequestHeader(val, key) {
|
||||||
if (!data && key.toLowerCase() === 'content-type') {
|
if (!data && key.toLowerCase() === 'content-type') {
|
||||||
delete requestHeaders[key];
|
// Remove Content-Type if data is undefined
|
||||||
}
|
delete requestHeaders[key];
|
||||||
// Otherwise add header to the request
|
} else {
|
||||||
else {
|
// Otherwise add header to the request
|
||||||
request.setRequestHeader(key, val);
|
request.setRequestHeader(key, val);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
}
|
||||||
|
|
||||||
// Add withCredentials to request if needed
|
// Add withCredentials to request if needed
|
||||||
if (config.withCredentials) {
|
if (config.withCredentials) {
|
||||||
@@ -727,7 +655,7 @@ return /******/ (function(modules) { // webpackBootstrap
|
|||||||
|
|
||||||
|
|
||||||
/***/ },
|
/***/ },
|
||||||
/* 7 */
|
/* 6 */
|
||||||
/***/ function(module, exports, __webpack_require__) {
|
/***/ function(module, exports, __webpack_require__) {
|
||||||
|
|
||||||
'use strict';
|
'use strict';
|
||||||
@@ -752,47 +680,55 @@ return /******/ (function(modules) { // webpackBootstrap
|
|||||||
* @param {object} [params] The params to be appended
|
* @param {object} [params] The params to be appended
|
||||||
* @returns {string} The formatted url
|
* @returns {string} The formatted url
|
||||||
*/
|
*/
|
||||||
module.exports = function buildUrl(url, params) {
|
module.exports = function buildURL(url, params, paramsSerializer) {
|
||||||
|
/*eslint no-param-reassign:0*/
|
||||||
if (!params) {
|
if (!params) {
|
||||||
return url;
|
return url;
|
||||||
}
|
}
|
||||||
|
|
||||||
var parts = [];
|
var serializedParams;
|
||||||
|
if (paramsSerializer) {
|
||||||
|
serializedParams = paramsSerializer(params);
|
||||||
|
} else {
|
||||||
|
var parts = [];
|
||||||
|
|
||||||
utils.forEach(params, function (val, key) {
|
utils.forEach(params, function serialize(val, key) {
|
||||||
if (val === null || typeof val === 'undefined') {
|
if (val === null || typeof val === 'undefined') {
|
||||||
return;
|
return;
|
||||||
}
|
|
||||||
|
|
||||||
if (utils.isArray(val)) {
|
|
||||||
key = key + '[]';
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!utils.isArray(val)) {
|
|
||||||
val = [val];
|
|
||||||
}
|
|
||||||
|
|
||||||
utils.forEach(val, function (v) {
|
|
||||||
if (utils.isDate(v)) {
|
|
||||||
v = v.toISOString();
|
|
||||||
}
|
}
|
||||||
else if (utils.isObject(v)) {
|
|
||||||
v = JSON.stringify(v);
|
if (utils.isArray(val)) {
|
||||||
|
key = key + '[]';
|
||||||
}
|
}
|
||||||
parts.push(encode(key) + '=' + encode(v));
|
|
||||||
|
if (!utils.isArray(val)) {
|
||||||
|
val = [val];
|
||||||
|
}
|
||||||
|
|
||||||
|
utils.forEach(val, function parseValue(v) {
|
||||||
|
if (utils.isDate(v)) {
|
||||||
|
v = v.toISOString();
|
||||||
|
} else if (utils.isObject(v)) {
|
||||||
|
v = JSON.stringify(v);
|
||||||
|
}
|
||||||
|
parts.push(encode(key) + '=' + encode(v));
|
||||||
|
});
|
||||||
});
|
});
|
||||||
});
|
|
||||||
|
|
||||||
if (parts.length > 0) {
|
serializedParams = parts.join('&');
|
||||||
url += (url.indexOf('?') === -1 ? '?' : '&') + parts.join('&');
|
}
|
||||||
|
|
||||||
|
if (serializedParams) {
|
||||||
|
url += (url.indexOf('?') === -1 ? '?' : '&') + serializedParams;
|
||||||
}
|
}
|
||||||
|
|
||||||
return url;
|
return url;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/***/ },
|
/***/ },
|
||||||
/* 8 */
|
/* 7 */
|
||||||
/***/ function(module, exports, __webpack_require__) {
|
/***/ function(module, exports, __webpack_require__) {
|
||||||
|
|
||||||
'use strict';
|
'use strict';
|
||||||
@@ -813,11 +749,14 @@ return /******/ (function(modules) { // webpackBootstrap
|
|||||||
* @returns {Object} Headers parsed into an object
|
* @returns {Object} Headers parsed into an object
|
||||||
*/
|
*/
|
||||||
module.exports = function parseHeaders(headers) {
|
module.exports = function parseHeaders(headers) {
|
||||||
var parsed = {}, key, val, i;
|
var parsed = {};
|
||||||
|
var key;
|
||||||
|
var val;
|
||||||
|
var i;
|
||||||
|
|
||||||
if (!headers) { return parsed; }
|
if (!headers) { return parsed; }
|
||||||
|
|
||||||
utils.forEach(headers.split('\n'), function(line) {
|
utils.forEach(headers.split('\n'), function parser(line) {
|
||||||
i = line.indexOf(':');
|
i = line.indexOf(':');
|
||||||
key = utils.trim(line.substr(0, i)).toLowerCase();
|
key = utils.trim(line.substr(0, i)).toLowerCase();
|
||||||
val = utils.trim(line.substr(i + 1));
|
val = utils.trim(line.substr(i + 1));
|
||||||
@@ -832,7 +771,7 @@ return /******/ (function(modules) { // webpackBootstrap
|
|||||||
|
|
||||||
|
|
||||||
/***/ },
|
/***/ },
|
||||||
/* 9 */
|
/* 8 */
|
||||||
/***/ function(module, exports, __webpack_require__) {
|
/***/ function(module, exports, __webpack_require__) {
|
||||||
|
|
||||||
'use strict';
|
'use strict';
|
||||||
@@ -848,7 +787,8 @@ return /******/ (function(modules) { // webpackBootstrap
|
|||||||
* @returns {*} The resulting transformed data
|
* @returns {*} The resulting transformed data
|
||||||
*/
|
*/
|
||||||
module.exports = function transformData(data, headers, fns) {
|
module.exports = function transformData(data, headers, fns) {
|
||||||
utils.forEach(fns, function (fn) {
|
/*eslint no-param-reassign:0*/
|
||||||
|
utils.forEach(fns, function transform(fn) {
|
||||||
data = fn(data, headers);
|
data = fn(data, headers);
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -857,52 +797,119 @@ return /******/ (function(modules) { // webpackBootstrap
|
|||||||
|
|
||||||
|
|
||||||
/***/ },
|
/***/ },
|
||||||
/* 10 */
|
/* 9 */
|
||||||
/***/ function(module, exports, __webpack_require__) {
|
/***/ function(module, exports, __webpack_require__) {
|
||||||
|
|
||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
/**
|
|
||||||
* WARNING:
|
|
||||||
* This file makes references to objects that aren't safe in all environments.
|
|
||||||
* Please see lib/utils.isStandardBrowserEnv before including this file.
|
|
||||||
*/
|
|
||||||
|
|
||||||
var utils = __webpack_require__(3);
|
var utils = __webpack_require__(3);
|
||||||
|
|
||||||
module.exports = {
|
module.exports = (
|
||||||
write: function write(name, value, expires, path, domain, secure) {
|
utils.isStandardBrowserEnv() ?
|
||||||
var cookie = [];
|
|
||||||
cookie.push(name + '=' + encodeURIComponent(value));
|
|
||||||
|
|
||||||
if (utils.isNumber(expires)) {
|
// Standard browser envs have full support of the APIs needed to test
|
||||||
cookie.push('expires=' + new Date(expires).toGMTString());
|
// whether the request URL is of the same origin as current location.
|
||||||
|
(function standardBrowserEnv() {
|
||||||
|
var msie = /(msie|trident)/i.test(navigator.userAgent);
|
||||||
|
var urlParsingNode = document.createElement('a');
|
||||||
|
var originURL;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Parse a URL to discover it's components
|
||||||
|
*
|
||||||
|
* @param {String} url The URL to be parsed
|
||||||
|
* @returns {Object}
|
||||||
|
*/
|
||||||
|
function resolveURL(url) {
|
||||||
|
var href = url;
|
||||||
|
|
||||||
|
if (msie) {
|
||||||
|
// IE needs attribute set twice to normalize properties
|
||||||
|
urlParsingNode.setAttribute('href', href);
|
||||||
|
href = urlParsingNode.href;
|
||||||
|
}
|
||||||
|
|
||||||
|
urlParsingNode.setAttribute('href', href);
|
||||||
|
|
||||||
|
// urlParsingNode provides the UrlUtils interface - http://url.spec.whatwg.org/#urlutils
|
||||||
|
return {
|
||||||
|
href: urlParsingNode.href,
|
||||||
|
protocol: urlParsingNode.protocol ? urlParsingNode.protocol.replace(/:$/, '') : '',
|
||||||
|
host: urlParsingNode.host,
|
||||||
|
search: urlParsingNode.search ? urlParsingNode.search.replace(/^\?/, '') : '',
|
||||||
|
hash: urlParsingNode.hash ? urlParsingNode.hash.replace(/^#/, '') : '',
|
||||||
|
hostname: urlParsingNode.hostname,
|
||||||
|
port: urlParsingNode.port,
|
||||||
|
pathname: (urlParsingNode.pathname.charAt(0) === '/') ?
|
||||||
|
urlParsingNode.pathname :
|
||||||
|
'/' + urlParsingNode.pathname
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
if (utils.isString(path)) {
|
originURL = resolveURL(window.location.href);
|
||||||
cookie.push('path=' + path);
|
|
||||||
|
/**
|
||||||
|
* Determine if a URL shares the same origin as the current location
|
||||||
|
*
|
||||||
|
* @param {String} requestURL The URL to test
|
||||||
|
* @returns {boolean} True if URL shares the same origin, otherwise false
|
||||||
|
*/
|
||||||
|
return function isURLSameOrigin(requestURL) {
|
||||||
|
var parsed = (utils.isString(requestURL)) ? resolveURL(requestURL) : requestURL;
|
||||||
|
return (parsed.protocol === originURL.protocol &&
|
||||||
|
parsed.host === originURL.host);
|
||||||
|
};
|
||||||
|
})() :
|
||||||
|
|
||||||
|
// Non standard browser envs (web workers, react-native) lack needed support.
|
||||||
|
(function nonStandardBrowserEnv() {
|
||||||
|
return function isURLSameOrigin() {
|
||||||
|
return true;
|
||||||
|
};
|
||||||
|
})()
|
||||||
|
);
|
||||||
|
|
||||||
|
|
||||||
|
/***/ },
|
||||||
|
/* 10 */
|
||||||
|
/***/ function(module, exports) {
|
||||||
|
|
||||||
|
'use strict';
|
||||||
|
|
||||||
|
// btoa polyfill for IE<10 courtesy https://github.com/davidchambers/Base64.js
|
||||||
|
|
||||||
|
var chars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=';
|
||||||
|
|
||||||
|
function InvalidCharacterError(message) {
|
||||||
|
this.message = message;
|
||||||
|
}
|
||||||
|
InvalidCharacterError.prototype = new Error;
|
||||||
|
InvalidCharacterError.prototype.code = 5;
|
||||||
|
InvalidCharacterError.prototype.name = 'InvalidCharacterError';
|
||||||
|
|
||||||
|
function btoa(input) {
|
||||||
|
var str = String(input);
|
||||||
|
var output = '';
|
||||||
|
for (
|
||||||
|
// initialize result and counter
|
||||||
|
var block, charCode, idx = 0, map = chars;
|
||||||
|
// if the next str index does not exist:
|
||||||
|
// change the mapping table to "="
|
||||||
|
// check if d has no fractional digits
|
||||||
|
str.charAt(idx | 0) || (map = '=', idx % 1);
|
||||||
|
// "8 - idx % 1 * 8" generates the sequence 2, 4, 6, 8
|
||||||
|
output += map.charAt(63 & block >> 8 - idx % 1 * 8)
|
||||||
|
) {
|
||||||
|
charCode = str.charCodeAt(idx += 3 / 4);
|
||||||
|
if (charCode > 0xFF) {
|
||||||
|
throw new InvalidCharacterError('INVALID_CHARACTER_ERR: DOM Exception 5');
|
||||||
}
|
}
|
||||||
|
block = block << 8 | charCode;
|
||||||
if (utils.isString(domain)) {
|
|
||||||
cookie.push('domain=' + domain);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (secure === true) {
|
|
||||||
cookie.push('secure');
|
|
||||||
}
|
|
||||||
|
|
||||||
document.cookie = cookie.join('; ');
|
|
||||||
},
|
|
||||||
|
|
||||||
read: function read(name) {
|
|
||||||
var match = document.cookie.match(new RegExp('(^|;\\s*)(' + name + ')=([^;]*)'));
|
|
||||||
return (match ? decodeURIComponent(match[3]) : null);
|
|
||||||
},
|
|
||||||
|
|
||||||
remove: function remove(name) {
|
|
||||||
this.write(name, '', Date.now() - 86400000);
|
|
||||||
}
|
}
|
||||||
};
|
return output;
|
||||||
|
}
|
||||||
|
|
||||||
|
module.exports = btoa;
|
||||||
|
|
||||||
|
|
||||||
/***/ },
|
/***/ },
|
||||||
@@ -911,62 +918,57 @@ return /******/ (function(modules) { // webpackBootstrap
|
|||||||
|
|
||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
/**
|
|
||||||
* WARNING:
|
|
||||||
* This file makes references to objects that aren't safe in all environments.
|
|
||||||
* Please see lib/utils.isStandardBrowserEnv before including this file.
|
|
||||||
*/
|
|
||||||
|
|
||||||
var utils = __webpack_require__(3);
|
var utils = __webpack_require__(3);
|
||||||
var msie = /(msie|trident)/i.test(navigator.userAgent);
|
|
||||||
var urlParsingNode = document.createElement('a');
|
|
||||||
var originUrl;
|
|
||||||
|
|
||||||
/**
|
module.exports = (
|
||||||
* Parse a URL to discover it's components
|
utils.isStandardBrowserEnv() ?
|
||||||
*
|
|
||||||
* @param {String} url The URL to be parsed
|
|
||||||
* @returns {Object}
|
|
||||||
*/
|
|
||||||
function urlResolve(url) {
|
|
||||||
var href = url;
|
|
||||||
|
|
||||||
if (msie) {
|
// Standard browser envs support document.cookie
|
||||||
// IE needs attribute set twice to normalize properties
|
(function standardBrowserEnv() {
|
||||||
urlParsingNode.setAttribute('href', href);
|
return {
|
||||||
href = urlParsingNode.href;
|
write: function write(name, value, expires, path, domain, secure) {
|
||||||
}
|
var cookie = [];
|
||||||
|
cookie.push(name + '=' + encodeURIComponent(value));
|
||||||
|
|
||||||
urlParsingNode.setAttribute('href', href);
|
if (utils.isNumber(expires)) {
|
||||||
|
cookie.push('expires=' + new Date(expires).toGMTString());
|
||||||
|
}
|
||||||
|
|
||||||
// urlParsingNode provides the UrlUtils interface - http://url.spec.whatwg.org/#urlutils
|
if (utils.isString(path)) {
|
||||||
return {
|
cookie.push('path=' + path);
|
||||||
href: urlParsingNode.href,
|
}
|
||||||
protocol: urlParsingNode.protocol ? urlParsingNode.protocol.replace(/:$/, '') : '',
|
|
||||||
host: urlParsingNode.host,
|
|
||||||
search: urlParsingNode.search ? urlParsingNode.search.replace(/^\?/, '') : '',
|
|
||||||
hash: urlParsingNode.hash ? urlParsingNode.hash.replace(/^#/, '') : '',
|
|
||||||
hostname: urlParsingNode.hostname,
|
|
||||||
port: urlParsingNode.port,
|
|
||||||
pathname: (urlParsingNode.pathname.charAt(0) === '/') ?
|
|
||||||
urlParsingNode.pathname :
|
|
||||||
'/' + urlParsingNode.pathname
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
originUrl = urlResolve(window.location.href);
|
if (utils.isString(domain)) {
|
||||||
|
cookie.push('domain=' + domain);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
if (secure === true) {
|
||||||
* Determine if a URL shares the same origin as the current location
|
cookie.push('secure');
|
||||||
*
|
}
|
||||||
* @param {String} requestUrl The URL to test
|
|
||||||
* @returns {boolean} True if URL shares the same origin, otherwise false
|
document.cookie = cookie.join('; ');
|
||||||
*/
|
},
|
||||||
module.exports = function urlIsSameOrigin(requestUrl) {
|
|
||||||
var parsed = (utils.isString(requestUrl)) ? urlResolve(requestUrl) : requestUrl;
|
read: function read(name) {
|
||||||
return (parsed.protocol === originUrl.protocol &&
|
var match = document.cookie.match(new RegExp('(^|;\\s*)(' + name + ')=([^;]*)'));
|
||||||
parsed.host === originUrl.host);
|
return (match ? decodeURIComponent(match[3]) : null);
|
||||||
};
|
},
|
||||||
|
|
||||||
|
remove: function remove(name) {
|
||||||
|
this.write(name, '', Date.now() - 86400000);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
})() :
|
||||||
|
|
||||||
|
// Non standard browser env (web workers, react-native) lack needed support.
|
||||||
|
(function nonStandardBrowserEnv() {
|
||||||
|
return {
|
||||||
|
write: function write() {},
|
||||||
|
read: function read() { return null; },
|
||||||
|
remove: function remove() {}
|
||||||
|
};
|
||||||
|
})()
|
||||||
|
);
|
||||||
|
|
||||||
|
|
||||||
/***/ },
|
/***/ },
|
||||||
@@ -989,7 +991,7 @@ return /******/ (function(modules) { // webpackBootstrap
|
|||||||
*
|
*
|
||||||
* @return {Number} An ID used to remove interceptor later
|
* @return {Number} An ID used to remove interceptor later
|
||||||
*/
|
*/
|
||||||
InterceptorManager.prototype.use = function (fulfilled, rejected) {
|
InterceptorManager.prototype.use = function use(fulfilled, rejected) {
|
||||||
this.handlers.push({
|
this.handlers.push({
|
||||||
fulfilled: fulfilled,
|
fulfilled: fulfilled,
|
||||||
rejected: rejected
|
rejected: rejected
|
||||||
@@ -1002,7 +1004,7 @@ return /******/ (function(modules) { // webpackBootstrap
|
|||||||
*
|
*
|
||||||
* @param {Number} id The ID that was returned by `use`
|
* @param {Number} id The ID that was returned by `use`
|
||||||
*/
|
*/
|
||||||
InterceptorManager.prototype.eject = function (id) {
|
InterceptorManager.prototype.eject = function eject(id) {
|
||||||
if (this.handlers[id]) {
|
if (this.handlers[id]) {
|
||||||
this.handlers[id] = null;
|
this.handlers[id] = null;
|
||||||
}
|
}
|
||||||
@@ -1012,12 +1014,12 @@ return /******/ (function(modules) { // webpackBootstrap
|
|||||||
* Iterate over all the registered interceptors
|
* Iterate over all the registered interceptors
|
||||||
*
|
*
|
||||||
* This method is particularly useful for skipping over any
|
* This method is particularly useful for skipping over any
|
||||||
* interceptors that may have become `null` calling `remove`.
|
* interceptors that may have become `null` calling `eject`.
|
||||||
*
|
*
|
||||||
* @param {Function} fn The function to call for each interceptor
|
* @param {Function} fn The function to call for each interceptor
|
||||||
*/
|
*/
|
||||||
InterceptorManager.prototype.forEach = function (fn) {
|
InterceptorManager.prototype.forEach = function forEach(fn) {
|
||||||
utils.forEach(this.handlers, function (h) {
|
utils.forEach(this.handlers, function forEachHandler(h) {
|
||||||
if (h !== null) {
|
if (h !== null) {
|
||||||
fn(h);
|
fn(h);
|
||||||
}
|
}
|
||||||
@@ -1033,6 +1035,61 @@ return /******/ (function(modules) { // webpackBootstrap
|
|||||||
|
|
||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Determines whether the specified URL is absolute
|
||||||
|
*
|
||||||
|
* @param {string} url The URL to test
|
||||||
|
* @returns {boolean} True if the specified URL is absolute, otherwise false
|
||||||
|
*/
|
||||||
|
module.exports = function isAbsoluteURL(url) {
|
||||||
|
// A URL is considered absolute if it begins with "<scheme>://" or "//" (protocol-relative URL).
|
||||||
|
// RFC 3986 defines scheme name as a sequence of characters beginning with a letter and followed
|
||||||
|
// by any combination of letters, digits, plus, period, or hyphen.
|
||||||
|
return /^([a-z][a-z\d\+\-\.]*:)?\/\//i.test(url);
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
/***/ },
|
||||||
|
/* 14 */
|
||||||
|
/***/ function(module, exports) {
|
||||||
|
|
||||||
|
'use strict';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates a new URL by combining the specified URLs
|
||||||
|
*
|
||||||
|
* @param {string} baseURL The base URL
|
||||||
|
* @param {string} relativeURL The relative URL
|
||||||
|
* @returns {string} The combined URL
|
||||||
|
*/
|
||||||
|
module.exports = function combineURLs(baseURL, relativeURL) {
|
||||||
|
return baseURL.replace(/\/+$/, '') + '/' + relativeURL.replace(/^\/+/, '');
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
/***/ },
|
||||||
|
/* 15 */
|
||||||
|
/***/ function(module, exports) {
|
||||||
|
|
||||||
|
'use strict';
|
||||||
|
|
||||||
|
module.exports = function bind(fn, thisArg) {
|
||||||
|
return function wrap() {
|
||||||
|
var args = new Array(arguments.length);
|
||||||
|
for (var i = 0; i < args.length; i++) {
|
||||||
|
args[i] = arguments[i];
|
||||||
|
}
|
||||||
|
return fn.apply(thisArg, args);
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
/***/ },
|
||||||
|
/* 16 */
|
||||||
|
/***/ function(module, exports) {
|
||||||
|
|
||||||
|
'use strict';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Syntactic sugar for invoking a function and expanding an array for arguments.
|
* Syntactic sugar for invoking a function and expanding an array for arguments.
|
||||||
*
|
*
|
||||||
@@ -1054,7 +1111,7 @@ return /******/ (function(modules) { // webpackBootstrap
|
|||||||
* @returns {Function}
|
* @returns {Function}
|
||||||
*/
|
*/
|
||||||
module.exports = function spread(callback) {
|
module.exports = function spread(callback) {
|
||||||
return function (arr) {
|
return function wrap(arr) {
|
||||||
return callback.apply(null, arr);
|
return callback.apply(null, arr);
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|||||||
Vendored
+1
-1
File diff suppressed because one or more lines are too long
Vendored
+2
-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
+1
-1
@@ -10,7 +10,7 @@ module.exports = function(config) {
|
|||||||
|
|
||||||
// frameworks to use
|
// frameworks to use
|
||||||
// available frameworks: https://npmjs.org/browse/keyword/karma-adapter
|
// available frameworks: https://npmjs.org/browse/keyword/karma-adapter
|
||||||
frameworks: ['jasmine-ajax', 'jasmine'],
|
frameworks: ['jasmine-ajax', 'jasmine', 'sinon'],
|
||||||
|
|
||||||
|
|
||||||
// list of files / patterns to load in the browser
|
// list of files / patterns to load in the browser
|
||||||
|
|||||||
+42
-25
@@ -1,29 +1,18 @@
|
|||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
var defaults = require('./../defaults');
|
|
||||||
var utils = require('./../utils');
|
var utils = require('./../utils');
|
||||||
var buildUrl = require('./../helpers/buildUrl');
|
var buildURL = require('./../helpers/buildURL');
|
||||||
var transformData = require('./../helpers/transformData');
|
var transformData = require('./../helpers/transformData');
|
||||||
var http = require('http');
|
var http = require('follow-redirects').http;
|
||||||
var https = require('https');
|
var https = require('follow-redirects').https;
|
||||||
var url = require('url');
|
var url = require('url');
|
||||||
|
var zlib = require('zlib');
|
||||||
var pkg = require('./../../package.json');
|
var pkg = require('./../../package.json');
|
||||||
var Buffer = require('buffer').Buffer;
|
var Buffer = require('buffer').Buffer;
|
||||||
|
|
||||||
module.exports = function httpAdapter(resolve, reject, config) {
|
module.exports = function httpAdapter(resolve, reject, config) {
|
||||||
// Transform request data
|
var data = config.data;
|
||||||
var data = transformData(
|
var headers = config.headers;
|
||||||
config.data,
|
|
||||||
config.headers,
|
|
||||||
config.transformRequest
|
|
||||||
);
|
|
||||||
|
|
||||||
// Merge headers
|
|
||||||
var headers = utils.merge(
|
|
||||||
defaults.headers.common,
|
|
||||||
defaults.headers[config.method] || {},
|
|
||||||
config.headers || {}
|
|
||||||
);
|
|
||||||
|
|
||||||
// Set User-Agent (required by some servers)
|
// Set User-Agent (required by some servers)
|
||||||
// Only set header if it hasn't been set in config
|
// Only set header if it hasn't been set in config
|
||||||
@@ -45,29 +34,57 @@ module.exports = function httpAdapter(resolve, reject, config) {
|
|||||||
headers['Content-Length'] = data.length;
|
headers['Content-Length'] = data.length;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// HTTP basic authentication
|
||||||
|
var auth = undefined;
|
||||||
|
if (config.auth) {
|
||||||
|
var username = config.auth.username || '';
|
||||||
|
var password = config.auth.password || '';
|
||||||
|
auth = username + ':' + password;
|
||||||
|
}
|
||||||
|
|
||||||
// Parse url
|
// Parse url
|
||||||
var parsed = url.parse(config.url);
|
var parsed = url.parse(config.url);
|
||||||
var options = {
|
var options = {
|
||||||
host: parsed.hostname,
|
host: parsed.hostname,
|
||||||
port: parsed.port,
|
port: parsed.port,
|
||||||
path: buildUrl(parsed.path, config.params).replace(/^\?/, ''),
|
path: buildURL(parsed.path, config.params, config.paramsSerializer).replace(/^\?/, ''),
|
||||||
method: config.method,
|
method: config.method,
|
||||||
headers: headers,
|
headers: headers,
|
||||||
agent: config.agent
|
agent: config.agent,
|
||||||
|
auth: auth
|
||||||
};
|
};
|
||||||
|
|
||||||
// Create the request
|
// Create the request
|
||||||
var transport = parsed.protocol === 'https:' ? https : http;
|
var transport = parsed.protocol === 'https:' ? https : http;
|
||||||
var req = transport.request(options, function (res) {
|
var req = transport.request(options, function handleResponse(res) {
|
||||||
|
// uncompress the response body transparently if required
|
||||||
|
var stream = res;
|
||||||
|
switch (res.headers['content-encoding']) {
|
||||||
|
/*eslint default-case:0*/
|
||||||
|
case 'gzip':
|
||||||
|
case 'compress':
|
||||||
|
case 'deflate':
|
||||||
|
// add the unzipper to the body stream processing pipeline
|
||||||
|
stream = stream.pipe(zlib.createUnzip());
|
||||||
|
|
||||||
|
// remove the content-encoding in order to not confuse downstream operations
|
||||||
|
delete res.headers['content-encoding'];
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
var responseBuffer = [];
|
var responseBuffer = [];
|
||||||
res.on('data', function (chunk) {
|
stream.on('data', function handleStreamData(chunk) {
|
||||||
responseBuffer.push(chunk);
|
responseBuffer.push(chunk);
|
||||||
});
|
});
|
||||||
|
|
||||||
res.on('end', function () {
|
stream.on('end', function handleStreamEnd() {
|
||||||
|
var d = Buffer.concat(responseBuffer);
|
||||||
|
if (config.responseType !== 'arraybuffer') {
|
||||||
|
d = d.toString('utf8');
|
||||||
|
}
|
||||||
var response = {
|
var response = {
|
||||||
data: transformData(
|
data: transformData(
|
||||||
Buffer.concat(responseBuffer).toString('utf8'),
|
d,
|
||||||
res.headers,
|
res.headers,
|
||||||
config.transformResponse
|
config.transformResponse
|
||||||
),
|
),
|
||||||
@@ -85,12 +102,12 @@ module.exports = function httpAdapter(resolve, reject, config) {
|
|||||||
});
|
});
|
||||||
|
|
||||||
// Handle errors
|
// Handle errors
|
||||||
req.on('error', function (err) {
|
req.on('error', function handleRequestError(err) {
|
||||||
reject(err);
|
reject(err);
|
||||||
});
|
});
|
||||||
|
|
||||||
// Handle request timeout
|
// Handle request timeout
|
||||||
req.setTimeout(config.timeout, function () {
|
req.setTimeout(config.timeout, function handleRequestTimeout() {
|
||||||
req.abort();
|
req.abort();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
+48
-40
@@ -2,43 +2,52 @@
|
|||||||
|
|
||||||
/*global ActiveXObject:true*/
|
/*global ActiveXObject:true*/
|
||||||
|
|
||||||
var defaults = require('./../defaults');
|
|
||||||
var utils = require('./../utils');
|
var utils = require('./../utils');
|
||||||
var buildUrl = require('./../helpers/buildUrl');
|
var buildURL = require('./../helpers/buildURL');
|
||||||
var parseHeaders = require('./../helpers/parseHeaders');
|
var parseHeaders = require('./../helpers/parseHeaders');
|
||||||
var transformData = require('./../helpers/transformData');
|
var transformData = require('./../helpers/transformData');
|
||||||
|
var isURLSameOrigin = require('./../helpers/isURLSameOrigin');
|
||||||
|
var ieVersion = require('./../helpers/ieVersion');
|
||||||
|
var btoa = window.btoa || require('./../helpers/btoa');
|
||||||
|
|
||||||
module.exports = function xhrAdapter(resolve, reject, config) {
|
module.exports = function xhrAdapter(resolve, reject, config) {
|
||||||
// Transform request data
|
var requestData = config.data;
|
||||||
var data = transformData(
|
var requestHeaders = config.headers;
|
||||||
config.data,
|
|
||||||
config.headers,
|
|
||||||
config.transformRequest
|
|
||||||
);
|
|
||||||
|
|
||||||
// Merge headers
|
if (utils.isFormData(requestData)) {
|
||||||
var requestHeaders = utils.merge(
|
|
||||||
defaults.headers.common,
|
|
||||||
defaults.headers[config.method] || {},
|
|
||||||
config.headers || {}
|
|
||||||
);
|
|
||||||
|
|
||||||
if (utils.isFormData(data)) {
|
|
||||||
delete requestHeaders['Content-Type']; // Let the browser set it
|
delete requestHeaders['Content-Type']; // Let the browser set it
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var Adapter = (XMLHttpRequest || ActiveXObject);
|
||||||
|
var loadEvent = 'onreadystatechange';
|
||||||
|
var xDomain = false;
|
||||||
|
|
||||||
|
// For IE 8/9 CORS support
|
||||||
|
if (ieVersion() <= 9 && !isURLSameOrigin(config.url) && window.XDomainRequest) {
|
||||||
|
Adapter = window.XDomainRequest;
|
||||||
|
loadEvent = 'onload';
|
||||||
|
xDomain = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
// HTTP basic authentication
|
||||||
|
if (config.auth) {
|
||||||
|
var username = config.auth.username || '';
|
||||||
|
var password = config.auth.password || '';
|
||||||
|
requestHeaders.Authorization = 'Basic ' + btoa(username + ':' + password);
|
||||||
|
}
|
||||||
|
|
||||||
// Create the request
|
// Create the request
|
||||||
var request = new (XMLHttpRequest || ActiveXObject)('Microsoft.XMLHTTP');
|
var request = new Adapter('Microsoft.XMLHTTP');
|
||||||
request.open(config.method.toUpperCase(), buildUrl(config.url, config.params), true);
|
request.open(config.method.toUpperCase(), buildURL(config.url, config.params, config.paramsSerializer), true);
|
||||||
|
|
||||||
// Set the request timeout in MS
|
// Set the request timeout in MS
|
||||||
request.timeout = config.timeout;
|
request.timeout = config.timeout;
|
||||||
|
|
||||||
// Listen for ready state
|
// Listen for ready state
|
||||||
request.onreadystatechange = function () {
|
request[loadEvent] = function handleReadyState() {
|
||||||
if (request && request.readyState === 4) {
|
if (request && (request.readyState === 4 || xDomain)) {
|
||||||
// Prepare the response
|
// Prepare the response
|
||||||
var responseHeaders = parseHeaders(request.getAllResponseHeaders());
|
var responseHeaders = xDomain ? null : parseHeaders(request.getAllResponseHeaders());
|
||||||
var responseData = ['text', ''].indexOf(config.responseType || '') !== -1 ? request.responseText : request.response;
|
var responseData = ['text', ''].indexOf(config.responseType || '') !== -1 ? request.responseText : request.response;
|
||||||
var response = {
|
var response = {
|
||||||
data: transformData(
|
data: transformData(
|
||||||
@@ -51,9 +60,8 @@ module.exports = function xhrAdapter(resolve, reject, config) {
|
|||||||
headers: responseHeaders,
|
headers: responseHeaders,
|
||||||
config: config
|
config: config
|
||||||
};
|
};
|
||||||
|
|
||||||
// Resolve or reject the Promise based on the status
|
// Resolve or reject the Promise based on the status
|
||||||
(request.status >= 200 && request.status < 300 ?
|
((request.status >= 200 && request.status < 300) || (xDomain && request.responseText) ?
|
||||||
resolve :
|
resolve :
|
||||||
reject)(response);
|
reject)(response);
|
||||||
|
|
||||||
@@ -67,29 +75,29 @@ module.exports = function xhrAdapter(resolve, reject, config) {
|
|||||||
// Specifically not if we're in a web worker, or react-native.
|
// Specifically not if we're in a web worker, or react-native.
|
||||||
if (utils.isStandardBrowserEnv()) {
|
if (utils.isStandardBrowserEnv()) {
|
||||||
var cookies = require('./../helpers/cookies');
|
var cookies = require('./../helpers/cookies');
|
||||||
var urlIsSameOrigin = require('./../helpers/urlIsSameOrigin');
|
|
||||||
|
|
||||||
// Add xsrf header
|
// Add xsrf header
|
||||||
var xsrfValue = urlIsSameOrigin(config.url) ?
|
var xsrfValue = config.withCredentials || isURLSameOrigin(config.url) ?
|
||||||
cookies.read(config.xsrfCookieName || defaults.xsrfCookieName) :
|
cookies.read(config.xsrfCookieName) :
|
||||||
undefined;
|
undefined;
|
||||||
|
|
||||||
if (xsrfValue) {
|
if (xsrfValue) {
|
||||||
requestHeaders[config.xsrfHeaderName || defaults.xsrfHeaderName] = xsrfValue;
|
requestHeaders[config.xsrfHeaderName] = xsrfValue;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Add headers to the request
|
// Add headers to the request
|
||||||
utils.forEach(requestHeaders, function (val, key) {
|
if (!xDomain) {
|
||||||
// Remove Content-Type if data is undefined
|
utils.forEach(requestHeaders, function setRequestHeader(val, key) {
|
||||||
if (!data && key.toLowerCase() === 'content-type') {
|
if (!requestData && key.toLowerCase() === 'content-type') {
|
||||||
delete requestHeaders[key];
|
// Remove Content-Type if data is undefined
|
||||||
}
|
delete requestHeaders[key];
|
||||||
// Otherwise add header to the request
|
} else {
|
||||||
else {
|
// Otherwise add header to the request
|
||||||
request.setRequestHeader(key, val);
|
request.setRequestHeader(key, val);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
}
|
||||||
|
|
||||||
// Add withCredentials to request if needed
|
// Add withCredentials to request if needed
|
||||||
if (config.withCredentials) {
|
if (config.withCredentials) {
|
||||||
@@ -107,10 +115,10 @@ module.exports = function xhrAdapter(resolve, reject, config) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (utils.isArrayBuffer(data)) {
|
if (utils.isArrayBuffer(requestData)) {
|
||||||
data = new DataView(data);
|
requestData = new DataView(requestData);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Send the request
|
// Send the request
|
||||||
request.send(data);
|
request.send(requestData);
|
||||||
};
|
};
|
||||||
|
|||||||
+75
-43
@@ -4,8 +4,21 @@ var defaults = require('./defaults');
|
|||||||
var utils = require('./utils');
|
var utils = require('./utils');
|
||||||
var dispatchRequest = require('./core/dispatchRequest');
|
var dispatchRequest = require('./core/dispatchRequest');
|
||||||
var InterceptorManager = require('./core/InterceptorManager');
|
var InterceptorManager = require('./core/InterceptorManager');
|
||||||
|
var isAbsoluteURL = require('./helpers/isAbsoluteURL');
|
||||||
|
var combineURLs = require('./helpers/combineURLs');
|
||||||
|
var bind = require('./helpers/bind');
|
||||||
|
var transformData = require('./helpers/transformData');
|
||||||
|
|
||||||
var axios = module.exports = function (config) {
|
function Axios(defaultConfig) {
|
||||||
|
this.defaults = utils.merge({}, defaultConfig);
|
||||||
|
this.interceptors = {
|
||||||
|
request: new InterceptorManager(),
|
||||||
|
response: new InterceptorManager()
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
Axios.prototype.request = function request(config) {
|
||||||
|
/*eslint no-param-reassign:0*/
|
||||||
// Allow for axios('example/url'[, config]) a la fetch API
|
// Allow for axios('example/url'[, config]) a la fetch API
|
||||||
if (typeof config === 'string') {
|
if (typeof config === 'string') {
|
||||||
config = utils.merge({
|
config = utils.merge({
|
||||||
@@ -13,26 +26,46 @@ var axios = module.exports = function (config) {
|
|||||||
}, arguments[1]);
|
}, arguments[1]);
|
||||||
}
|
}
|
||||||
|
|
||||||
config = utils.merge({
|
config = utils.merge(defaults, this.defaults, { method: 'get' }, config);
|
||||||
method: 'get',
|
|
||||||
headers: {},
|
// Support baseURL config
|
||||||
timeout: defaults.timeout,
|
if (config.baseURL && !isAbsoluteURL(config.url)) {
|
||||||
transformRequest: defaults.transformRequest,
|
config.url = combineURLs(config.baseURL, config.url);
|
||||||
transformResponse: defaults.transformResponse
|
}
|
||||||
}, config);
|
|
||||||
|
|
||||||
// Don't allow overriding defaults.withCredentials
|
// Don't allow overriding defaults.withCredentials
|
||||||
config.withCredentials = config.withCredentials || defaults.withCredentials;
|
config.withCredentials = config.withCredentials || this.defaults.withCredentials;
|
||||||
|
|
||||||
|
// Transform request data
|
||||||
|
config.data = transformData(
|
||||||
|
config.data,
|
||||||
|
config.headers,
|
||||||
|
config.transformRequest
|
||||||
|
);
|
||||||
|
|
||||||
|
// Flatten headers
|
||||||
|
config.headers = utils.merge(
|
||||||
|
config.headers.common || {},
|
||||||
|
config.headers[config.method] || {},
|
||||||
|
config.headers || {}
|
||||||
|
);
|
||||||
|
|
||||||
|
utils.forEach(
|
||||||
|
['delete', 'get', 'head', 'post', 'put', 'patch', 'common'],
|
||||||
|
function cleanHeaderConfig(method) {
|
||||||
|
delete config.headers[method];
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
// Hook up interceptors middleware
|
// Hook up interceptors middleware
|
||||||
var chain = [dispatchRequest, undefined];
|
var chain = [dispatchRequest, undefined];
|
||||||
var promise = Promise.resolve(config);
|
var promise = Promise.resolve(config);
|
||||||
|
|
||||||
axios.interceptors.request.forEach(function (interceptor) {
|
this.interceptors.request.forEach(function unshiftRequestInterceptors(interceptor) {
|
||||||
chain.unshift(interceptor.fulfilled, interceptor.rejected);
|
chain.unshift(interceptor.fulfilled, interceptor.rejected);
|
||||||
});
|
});
|
||||||
|
|
||||||
axios.interceptors.response.forEach(function (interceptor) {
|
this.interceptors.response.forEach(function pushResponseInterceptors(interceptor) {
|
||||||
chain.push(interceptor.fulfilled, interceptor.rejected);
|
chain.push(interceptor.fulfilled, interceptor.rejected);
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -43,46 +76,45 @@ var axios = module.exports = function (config) {
|
|||||||
return promise;
|
return promise;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
var defaultInstance = new Axios(defaults);
|
||||||
|
var axios = module.exports = bind(Axios.prototype.request, defaultInstance);
|
||||||
|
|
||||||
|
axios.create = function create(defaultConfig) {
|
||||||
|
return new Axios(defaultConfig);
|
||||||
|
};
|
||||||
|
|
||||||
// Expose defaults
|
// Expose defaults
|
||||||
axios.defaults = defaults;
|
axios.defaults = defaultInstance.defaults;
|
||||||
|
|
||||||
// Expose all/spread
|
// Expose all/spread
|
||||||
axios.all = function (promises) {
|
axios.all = function all(promises) {
|
||||||
return Promise.all(promises);
|
return Promise.all(promises);
|
||||||
};
|
};
|
||||||
axios.spread = require('./helpers/spread');
|
axios.spread = require('./helpers/spread');
|
||||||
|
|
||||||
// Expose interceptors
|
// Expose interceptors
|
||||||
axios.interceptors = {
|
axios.interceptors = defaultInstance.interceptors;
|
||||||
request: new InterceptorManager(),
|
|
||||||
response: new InterceptorManager()
|
|
||||||
};
|
|
||||||
|
|
||||||
// Provide aliases for supported request methods
|
// Provide aliases for supported request methods
|
||||||
(function () {
|
utils.forEach(['delete', 'get', 'head'], function forEachMethodNoData(method) {
|
||||||
function createShortMethods() {
|
/*eslint func-names:0*/
|
||||||
utils.forEach(arguments, function (method) {
|
Axios.prototype[method] = function(url, config) {
|
||||||
axios[method] = function (url, config) {
|
return this.request(utils.merge(config || {}, {
|
||||||
return axios(utils.merge(config || {}, {
|
method: method,
|
||||||
method: method,
|
url: url
|
||||||
url: url
|
}));
|
||||||
}));
|
};
|
||||||
};
|
axios[method] = bind(Axios.prototype[method], defaultInstance);
|
||||||
});
|
});
|
||||||
}
|
|
||||||
|
|
||||||
function createShortMethodsWithData() {
|
utils.forEach(['post', 'put', 'patch'], function forEachMethodWithData(method) {
|
||||||
utils.forEach(arguments, function (method) {
|
/*eslint func-names:0*/
|
||||||
axios[method] = function (url, data, config) {
|
Axios.prototype[method] = function(url, data, config) {
|
||||||
return axios(utils.merge(config || {}, {
|
return this.request(utils.merge(config || {}, {
|
||||||
method: method,
|
method: method,
|
||||||
url: url,
|
url: url,
|
||||||
data: data
|
data: data
|
||||||
}));
|
}));
|
||||||
};
|
};
|
||||||
});
|
axios[method] = bind(Axios.prototype[method], defaultInstance);
|
||||||
}
|
});
|
||||||
|
|
||||||
createShortMethods('delete', 'get', 'head');
|
|
||||||
createShortMethodsWithData('post', 'put', 'patch');
|
|
||||||
})();
|
|
||||||
|
|||||||
@@ -14,7 +14,7 @@ function InterceptorManager() {
|
|||||||
*
|
*
|
||||||
* @return {Number} An ID used to remove interceptor later
|
* @return {Number} An ID used to remove interceptor later
|
||||||
*/
|
*/
|
||||||
InterceptorManager.prototype.use = function (fulfilled, rejected) {
|
InterceptorManager.prototype.use = function use(fulfilled, rejected) {
|
||||||
this.handlers.push({
|
this.handlers.push({
|
||||||
fulfilled: fulfilled,
|
fulfilled: fulfilled,
|
||||||
rejected: rejected
|
rejected: rejected
|
||||||
@@ -27,7 +27,7 @@ InterceptorManager.prototype.use = function (fulfilled, rejected) {
|
|||||||
*
|
*
|
||||||
* @param {Number} id The ID that was returned by `use`
|
* @param {Number} id The ID that was returned by `use`
|
||||||
*/
|
*/
|
||||||
InterceptorManager.prototype.eject = function (id) {
|
InterceptorManager.prototype.eject = function eject(id) {
|
||||||
if (this.handlers[id]) {
|
if (this.handlers[id]) {
|
||||||
this.handlers[id] = null;
|
this.handlers[id] = null;
|
||||||
}
|
}
|
||||||
@@ -37,12 +37,12 @@ InterceptorManager.prototype.eject = function (id) {
|
|||||||
* Iterate over all the registered interceptors
|
* Iterate over all the registered interceptors
|
||||||
*
|
*
|
||||||
* This method is particularly useful for skipping over any
|
* This method is particularly useful for skipping over any
|
||||||
* interceptors that may have become `null` calling `remove`.
|
* interceptors that may have become `null` calling `eject`.
|
||||||
*
|
*
|
||||||
* @param {Function} fn The function to call for each interceptor
|
* @param {Function} fn The function to call for each interceptor
|
||||||
*/
|
*/
|
||||||
InterceptorManager.prototype.forEach = function (fn) {
|
InterceptorManager.prototype.forEach = function forEach(fn) {
|
||||||
utils.forEach(this.handlers, function (h) {
|
utils.forEach(this.handlers, function forEachHandler(h) {
|
||||||
if (h !== null) {
|
if (h !== null) {
|
||||||
fn(h);
|
fn(h);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -8,14 +8,13 @@
|
|||||||
* @returns {Promise} The Promise to be fulfilled
|
* @returns {Promise} The Promise to be fulfilled
|
||||||
*/
|
*/
|
||||||
module.exports = function dispatchRequest(config) {
|
module.exports = function dispatchRequest(config) {
|
||||||
return new Promise(function (resolve, reject) {
|
return new Promise(function executor(resolve, reject) {
|
||||||
try {
|
try {
|
||||||
// For browsers use XHR adapter
|
|
||||||
if ((typeof XMLHttpRequest !== 'undefined') || (typeof ActiveXObject !== 'undefined')) {
|
if ((typeof XMLHttpRequest !== 'undefined') || (typeof ActiveXObject !== 'undefined')) {
|
||||||
|
// For browsers use XHR adapter
|
||||||
require('../adapters/xhr')(resolve, reject, config);
|
require('../adapters/xhr')(resolve, reject, config);
|
||||||
}
|
} else if (typeof process !== 'undefined') {
|
||||||
// For node use HTTP adapter
|
// For node use HTTP adapter
|
||||||
else if (typeof process !== 'undefined') {
|
|
||||||
require('../adapters/http')(resolve, reject, config);
|
require('../adapters/http')(resolve, reject, config);
|
||||||
}
|
}
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
|
|||||||
+5
-4
@@ -8,8 +8,8 @@ var DEFAULT_CONTENT_TYPE = {
|
|||||||
};
|
};
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
transformRequest: [function (data, headers) {
|
transformRequest: [function transformResponseJSON(data, headers) {
|
||||||
if(utils.isFormData(data)) {
|
if (utils.isFormData(data)) {
|
||||||
return data;
|
return data;
|
||||||
}
|
}
|
||||||
if (utils.isArrayBuffer(data)) {
|
if (utils.isArrayBuffer(data)) {
|
||||||
@@ -21,7 +21,7 @@ module.exports = {
|
|||||||
if (utils.isObject(data) && !utils.isFile(data) && !utils.isBlob(data)) {
|
if (utils.isObject(data) && !utils.isFile(data) && !utils.isBlob(data)) {
|
||||||
// Set application/json if no Content-Type has been specified
|
// Set application/json if no Content-Type has been specified
|
||||||
if (!utils.isUndefined(headers)) {
|
if (!utils.isUndefined(headers)) {
|
||||||
utils.forEach(headers, function (val, key) {
|
utils.forEach(headers, function processContentTypeHeader(val, key) {
|
||||||
if (key.toLowerCase() === 'content-type') {
|
if (key.toLowerCase() === 'content-type') {
|
||||||
headers['Content-Type'] = val;
|
headers['Content-Type'] = val;
|
||||||
}
|
}
|
||||||
@@ -36,7 +36,8 @@ module.exports = {
|
|||||||
return data;
|
return data;
|
||||||
}],
|
}],
|
||||||
|
|
||||||
transformResponse: [function (data) {
|
transformResponse: [function transformResponseJSON(data) {
|
||||||
|
/*eslint no-param-reassign:0*/
|
||||||
if (typeof data === 'string') {
|
if (typeof data === 'string') {
|
||||||
data = data.replace(PROTECTION_PREFIX, '');
|
data = data.replace(PROTECTION_PREFIX, '');
|
||||||
try {
|
try {
|
||||||
|
|||||||
@@ -0,0 +1,11 @@
|
|||||||
|
'use strict';
|
||||||
|
|
||||||
|
module.exports = function bind(fn, thisArg) {
|
||||||
|
return function wrap() {
|
||||||
|
var args = new Array(arguments.length);
|
||||||
|
for (var i = 0; i < args.length; i++) {
|
||||||
|
args[i] = arguments[i];
|
||||||
|
}
|
||||||
|
return fn.apply(thisArg, args);
|
||||||
|
};
|
||||||
|
};
|
||||||
@@ -0,0 +1,36 @@
|
|||||||
|
'use strict';
|
||||||
|
|
||||||
|
// btoa polyfill for IE<10 courtesy https://github.com/davidchambers/Base64.js
|
||||||
|
|
||||||
|
var chars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=';
|
||||||
|
|
||||||
|
function InvalidCharacterError(message) {
|
||||||
|
this.message = message;
|
||||||
|
}
|
||||||
|
InvalidCharacterError.prototype = new Error;
|
||||||
|
InvalidCharacterError.prototype.code = 5;
|
||||||
|
InvalidCharacterError.prototype.name = 'InvalidCharacterError';
|
||||||
|
|
||||||
|
function btoa(input) {
|
||||||
|
var str = String(input);
|
||||||
|
var output = '';
|
||||||
|
for (
|
||||||
|
// initialize result and counter
|
||||||
|
var block, charCode, idx = 0, map = chars;
|
||||||
|
// if the next str index does not exist:
|
||||||
|
// change the mapping table to "="
|
||||||
|
// check if d has no fractional digits
|
||||||
|
str.charAt(idx | 0) || (map = '=', idx % 1);
|
||||||
|
// "8 - idx % 1 * 8" generates the sequence 2, 4, 6, 8
|
||||||
|
output += map.charAt(63 & block >> 8 - idx % 1 * 8)
|
||||||
|
) {
|
||||||
|
charCode = str.charCodeAt(idx += 3 / 4);
|
||||||
|
if (charCode > 0xFF) {
|
||||||
|
throw new InvalidCharacterError('INVALID_CHARACTER_ERR: DOM Exception 5');
|
||||||
|
}
|
||||||
|
block = block << 8 | charCode;
|
||||||
|
}
|
||||||
|
return output;
|
||||||
|
}
|
||||||
|
|
||||||
|
module.exports = btoa;
|
||||||
@@ -0,0 +1,67 @@
|
|||||||
|
'use strict';
|
||||||
|
|
||||||
|
var utils = require('./../utils');
|
||||||
|
|
||||||
|
function encode(val) {
|
||||||
|
return encodeURIComponent(val).
|
||||||
|
replace(/%40/gi, '@').
|
||||||
|
replace(/%3A/gi, ':').
|
||||||
|
replace(/%24/g, '$').
|
||||||
|
replace(/%2C/gi, ',').
|
||||||
|
replace(/%20/g, '+').
|
||||||
|
replace(/%5B/gi, '[').
|
||||||
|
replace(/%5D/gi, ']');
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Build a URL by appending params to the end
|
||||||
|
*
|
||||||
|
* @param {string} url The base of the url (e.g., http://www.google.com)
|
||||||
|
* @param {object} [params] The params to be appended
|
||||||
|
* @returns {string} The formatted url
|
||||||
|
*/
|
||||||
|
module.exports = function buildURL(url, params, paramsSerializer) {
|
||||||
|
/*eslint no-param-reassign:0*/
|
||||||
|
if (!params) {
|
||||||
|
return url;
|
||||||
|
}
|
||||||
|
|
||||||
|
var serializedParams;
|
||||||
|
if (paramsSerializer) {
|
||||||
|
serializedParams = paramsSerializer(params);
|
||||||
|
} else {
|
||||||
|
var parts = [];
|
||||||
|
|
||||||
|
utils.forEach(params, function serialize(val, key) {
|
||||||
|
if (val === null || typeof val === 'undefined') {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (utils.isArray(val)) {
|
||||||
|
key = key + '[]';
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!utils.isArray(val)) {
|
||||||
|
val = [val];
|
||||||
|
}
|
||||||
|
|
||||||
|
utils.forEach(val, function parseValue(v) {
|
||||||
|
if (utils.isDate(v)) {
|
||||||
|
v = v.toISOString();
|
||||||
|
} else if (utils.isObject(v)) {
|
||||||
|
v = JSON.stringify(v);
|
||||||
|
}
|
||||||
|
parts.push(encode(key) + '=' + encode(v));
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
serializedParams = parts.join('&');
|
||||||
|
}
|
||||||
|
|
||||||
|
if (serializedParams) {
|
||||||
|
url += (url.indexOf('?') === -1 ? '?' : '&') + serializedParams;
|
||||||
|
}
|
||||||
|
|
||||||
|
return url;
|
||||||
|
};
|
||||||
|
|
||||||
@@ -1,59 +0,0 @@
|
|||||||
'use strict';
|
|
||||||
|
|
||||||
var utils = require('./../utils');
|
|
||||||
|
|
||||||
function encode(val) {
|
|
||||||
return encodeURIComponent(val).
|
|
||||||
replace(/%40/gi, '@').
|
|
||||||
replace(/%3A/gi, ':').
|
|
||||||
replace(/%24/g, '$').
|
|
||||||
replace(/%2C/gi, ',').
|
|
||||||
replace(/%20/g, '+').
|
|
||||||
replace(/%5B/gi, '[').
|
|
||||||
replace(/%5D/gi, ']');
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Build a URL by appending params to the end
|
|
||||||
*
|
|
||||||
* @param {string} url The base of the url (e.g., http://www.google.com)
|
|
||||||
* @param {object} [params] The params to be appended
|
|
||||||
* @returns {string} The formatted url
|
|
||||||
*/
|
|
||||||
module.exports = function buildUrl(url, params) {
|
|
||||||
if (!params) {
|
|
||||||
return url;
|
|
||||||
}
|
|
||||||
|
|
||||||
var parts = [];
|
|
||||||
|
|
||||||
utils.forEach(params, function (val, key) {
|
|
||||||
if (val === null || typeof val === 'undefined') {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (utils.isArray(val)) {
|
|
||||||
key = key + '[]';
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!utils.isArray(val)) {
|
|
||||||
val = [val];
|
|
||||||
}
|
|
||||||
|
|
||||||
utils.forEach(val, function (v) {
|
|
||||||
if (utils.isDate(v)) {
|
|
||||||
v = v.toISOString();
|
|
||||||
}
|
|
||||||
else if (utils.isObject(v)) {
|
|
||||||
v = JSON.stringify(v);
|
|
||||||
}
|
|
||||||
parts.push(encode(key) + '=' + encode(v));
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
if (parts.length > 0) {
|
|
||||||
url += (url.indexOf('?') === -1 ? '?' : '&') + parts.join('&');
|
|
||||||
}
|
|
||||||
|
|
||||||
return url;
|
|
||||||
};
|
|
||||||
@@ -0,0 +1,12 @@
|
|||||||
|
'use strict';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates a new URL by combining the specified URLs
|
||||||
|
*
|
||||||
|
* @param {string} baseURL The base URL
|
||||||
|
* @param {string} relativeURL The relative URL
|
||||||
|
* @returns {string} The combined URL
|
||||||
|
*/
|
||||||
|
module.exports = function combineURLs(baseURL, relativeURL) {
|
||||||
|
return baseURL.replace(/\/+$/, '') + '/' + relativeURL.replace(/^\/+/, '');
|
||||||
|
};
|
||||||
+42
-32
@@ -1,43 +1,53 @@
|
|||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
/**
|
|
||||||
* WARNING:
|
|
||||||
* This file makes references to objects that aren't safe in all environments.
|
|
||||||
* Please see lib/utils.isStandardBrowserEnv before including this file.
|
|
||||||
*/
|
|
||||||
|
|
||||||
var utils = require('./../utils');
|
var utils = require('./../utils');
|
||||||
|
|
||||||
module.exports = {
|
module.exports = (
|
||||||
write: function write(name, value, expires, path, domain, secure) {
|
utils.isStandardBrowserEnv() ?
|
||||||
var cookie = [];
|
|
||||||
cookie.push(name + '=' + encodeURIComponent(value));
|
|
||||||
|
|
||||||
if (utils.isNumber(expires)) {
|
// Standard browser envs support document.cookie
|
||||||
cookie.push('expires=' + new Date(expires).toGMTString());
|
(function standardBrowserEnv() {
|
||||||
}
|
return {
|
||||||
|
write: function write(name, value, expires, path, domain, secure) {
|
||||||
|
var cookie = [];
|
||||||
|
cookie.push(name + '=' + encodeURIComponent(value));
|
||||||
|
|
||||||
if (utils.isString(path)) {
|
if (utils.isNumber(expires)) {
|
||||||
cookie.push('path=' + path);
|
cookie.push('expires=' + new Date(expires).toGMTString());
|
||||||
}
|
}
|
||||||
|
|
||||||
if (utils.isString(domain)) {
|
if (utils.isString(path)) {
|
||||||
cookie.push('domain=' + domain);
|
cookie.push('path=' + path);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (secure === true) {
|
if (utils.isString(domain)) {
|
||||||
cookie.push('secure');
|
cookie.push('domain=' + domain);
|
||||||
}
|
}
|
||||||
|
|
||||||
document.cookie = cookie.join('; ');
|
if (secure === true) {
|
||||||
},
|
cookie.push('secure');
|
||||||
|
}
|
||||||
|
|
||||||
read: function read(name) {
|
document.cookie = cookie.join('; ');
|
||||||
var match = document.cookie.match(new RegExp('(^|;\\s*)(' + name + ')=([^;]*)'));
|
},
|
||||||
return (match ? decodeURIComponent(match[3]) : null);
|
|
||||||
},
|
|
||||||
|
|
||||||
remove: function remove(name) {
|
read: function read(name) {
|
||||||
this.write(name, '', Date.now() - 86400000);
|
var match = document.cookie.match(new RegExp('(^|;\\s*)(' + name + ')=([^;]*)'));
|
||||||
}
|
return (match ? decodeURIComponent(match[3]) : null);
|
||||||
};
|
},
|
||||||
|
|
||||||
|
remove: function remove(name) {
|
||||||
|
this.write(name, '', Date.now() - 86400000);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
})() :
|
||||||
|
|
||||||
|
// Non standard browser env (web workers, react-native) lack needed support.
|
||||||
|
(function nonStandardBrowserEnv() {
|
||||||
|
return {
|
||||||
|
write: function write() {},
|
||||||
|
read: function read() { return null; },
|
||||||
|
remove: function remove() {}
|
||||||
|
};
|
||||||
|
})()
|
||||||
|
);
|
||||||
|
|||||||
@@ -1,5 +1,7 @@
|
|||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
|
/*eslint no-console:0*/
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Supply a warning to the developer that a method they are using
|
* Supply a warning to the developer that a method they are using
|
||||||
* has been deprecated.
|
* has been deprecated.
|
||||||
|
|||||||
@@ -0,0 +1,23 @@
|
|||||||
|
'use strict';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* https://gist.github.com/padolsey/527683
|
||||||
|
*
|
||||||
|
* A short snippet for detecting versions of IE in JavaScript
|
||||||
|
* without resorting to user-agent sniffing
|
||||||
|
*
|
||||||
|
* @returns {Number|undefined} Number of IE version (5-9), otherwise undefined
|
||||||
|
*/
|
||||||
|
module.exports = function ieVersion() {
|
||||||
|
var undef;
|
||||||
|
var v = 3;
|
||||||
|
var div = document.createElement('div');
|
||||||
|
var all = div.getElementsByTagName('i');
|
||||||
|
|
||||||
|
while ((
|
||||||
|
div.innerHTML = '<!--[if gt IE ' + (++v) + ']><i></i><![endif]-->',
|
||||||
|
all[0]
|
||||||
|
));
|
||||||
|
|
||||||
|
return v > 4 ? v : undef;
|
||||||
|
};
|
||||||
@@ -0,0 +1,14 @@
|
|||||||
|
'use strict';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Determines whether the specified URL is absolute
|
||||||
|
*
|
||||||
|
* @param {string} url The URL to test
|
||||||
|
* @returns {boolean} True if the specified URL is absolute, otherwise false
|
||||||
|
*/
|
||||||
|
module.exports = function isAbsoluteURL(url) {
|
||||||
|
// A URL is considered absolute if it begins with "<scheme>://" or "//" (protocol-relative URL).
|
||||||
|
// RFC 3986 defines scheme name as a sequence of characters beginning with a letter and followed
|
||||||
|
// by any combination of letters, digits, plus, period, or hyphen.
|
||||||
|
return /^([a-z][a-z\d\+\-\.]*:)?\/\//i.test(url);
|
||||||
|
};
|
||||||
@@ -0,0 +1,68 @@
|
|||||||
|
'use strict';
|
||||||
|
|
||||||
|
var utils = require('./../utils');
|
||||||
|
|
||||||
|
module.exports = (
|
||||||
|
utils.isStandardBrowserEnv() ?
|
||||||
|
|
||||||
|
// Standard browser envs have full support of the APIs needed to test
|
||||||
|
// whether the request URL is of the same origin as current location.
|
||||||
|
(function standardBrowserEnv() {
|
||||||
|
var msie = /(msie|trident)/i.test(navigator.userAgent);
|
||||||
|
var urlParsingNode = document.createElement('a');
|
||||||
|
var originURL;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Parse a URL to discover it's components
|
||||||
|
*
|
||||||
|
* @param {String} url The URL to be parsed
|
||||||
|
* @returns {Object}
|
||||||
|
*/
|
||||||
|
function resolveURL(url) {
|
||||||
|
var href = url;
|
||||||
|
|
||||||
|
if (msie) {
|
||||||
|
// IE needs attribute set twice to normalize properties
|
||||||
|
urlParsingNode.setAttribute('href', href);
|
||||||
|
href = urlParsingNode.href;
|
||||||
|
}
|
||||||
|
|
||||||
|
urlParsingNode.setAttribute('href', href);
|
||||||
|
|
||||||
|
// urlParsingNode provides the UrlUtils interface - http://url.spec.whatwg.org/#urlutils
|
||||||
|
return {
|
||||||
|
href: urlParsingNode.href,
|
||||||
|
protocol: urlParsingNode.protocol ? urlParsingNode.protocol.replace(/:$/, '') : '',
|
||||||
|
host: urlParsingNode.host,
|
||||||
|
search: urlParsingNode.search ? urlParsingNode.search.replace(/^\?/, '') : '',
|
||||||
|
hash: urlParsingNode.hash ? urlParsingNode.hash.replace(/^#/, '') : '',
|
||||||
|
hostname: urlParsingNode.hostname,
|
||||||
|
port: urlParsingNode.port,
|
||||||
|
pathname: (urlParsingNode.pathname.charAt(0) === '/') ?
|
||||||
|
urlParsingNode.pathname :
|
||||||
|
'/' + urlParsingNode.pathname
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
originURL = resolveURL(window.location.href);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Determine if a URL shares the same origin as the current location
|
||||||
|
*
|
||||||
|
* @param {String} requestURL The URL to test
|
||||||
|
* @returns {boolean} True if URL shares the same origin, otherwise false
|
||||||
|
*/
|
||||||
|
return function isURLSameOrigin(requestURL) {
|
||||||
|
var parsed = (utils.isString(requestURL)) ? resolveURL(requestURL) : requestURL;
|
||||||
|
return (parsed.protocol === originURL.protocol &&
|
||||||
|
parsed.host === originURL.host);
|
||||||
|
};
|
||||||
|
})() :
|
||||||
|
|
||||||
|
// Non standard browser envs (web workers, react-native) lack needed support.
|
||||||
|
(function nonStandardBrowserEnv() {
|
||||||
|
return function isURLSameOrigin() {
|
||||||
|
return true;
|
||||||
|
};
|
||||||
|
})()
|
||||||
|
);
|
||||||
@@ -16,11 +16,14 @@ var utils = require('./../utils');
|
|||||||
* @returns {Object} Headers parsed into an object
|
* @returns {Object} Headers parsed into an object
|
||||||
*/
|
*/
|
||||||
module.exports = function parseHeaders(headers) {
|
module.exports = function parseHeaders(headers) {
|
||||||
var parsed = {}, key, val, i;
|
var parsed = {};
|
||||||
|
var key;
|
||||||
|
var val;
|
||||||
|
var i;
|
||||||
|
|
||||||
if (!headers) { return parsed; }
|
if (!headers) { return parsed; }
|
||||||
|
|
||||||
utils.forEach(headers.split('\n'), function(line) {
|
utils.forEach(headers.split('\n'), function parser(line) {
|
||||||
i = line.indexOf(':');
|
i = line.indexOf(':');
|
||||||
key = utils.trim(line.substr(0, i)).toLowerCase();
|
key = utils.trim(line.substr(0, i)).toLowerCase();
|
||||||
val = utils.trim(line.substr(i + 1));
|
val = utils.trim(line.substr(i + 1));
|
||||||
|
|||||||
@@ -21,7 +21,7 @@
|
|||||||
* @returns {Function}
|
* @returns {Function}
|
||||||
*/
|
*/
|
||||||
module.exports = function spread(callback) {
|
module.exports = function spread(callback) {
|
||||||
return function (arr) {
|
return function wrap(arr) {
|
||||||
return callback.apply(null, arr);
|
return callback.apply(null, arr);
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -11,7 +11,8 @@ var utils = require('./../utils');
|
|||||||
* @returns {*} The resulting transformed data
|
* @returns {*} The resulting transformed data
|
||||||
*/
|
*/
|
||||||
module.exports = function transformData(data, headers, fns) {
|
module.exports = function transformData(data, headers, fns) {
|
||||||
utils.forEach(fns, function (fn) {
|
/*eslint no-param-reassign:0*/
|
||||||
|
utils.forEach(fns, function transform(fn) {
|
||||||
data = fn(data, headers);
|
data = fn(data, headers);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@@ -1,58 +0,0 @@
|
|||||||
'use strict';
|
|
||||||
|
|
||||||
/**
|
|
||||||
* WARNING:
|
|
||||||
* This file makes references to objects that aren't safe in all environments.
|
|
||||||
* Please see lib/utils.isStandardBrowserEnv before including this file.
|
|
||||||
*/
|
|
||||||
|
|
||||||
var utils = require('./../utils');
|
|
||||||
var msie = /(msie|trident)/i.test(navigator.userAgent);
|
|
||||||
var urlParsingNode = document.createElement('a');
|
|
||||||
var originUrl;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Parse a URL to discover it's components
|
|
||||||
*
|
|
||||||
* @param {String} url The URL to be parsed
|
|
||||||
* @returns {Object}
|
|
||||||
*/
|
|
||||||
function urlResolve(url) {
|
|
||||||
var href = url;
|
|
||||||
|
|
||||||
if (msie) {
|
|
||||||
// IE needs attribute set twice to normalize properties
|
|
||||||
urlParsingNode.setAttribute('href', href);
|
|
||||||
href = urlParsingNode.href;
|
|
||||||
}
|
|
||||||
|
|
||||||
urlParsingNode.setAttribute('href', href);
|
|
||||||
|
|
||||||
// urlParsingNode provides the UrlUtils interface - http://url.spec.whatwg.org/#urlutils
|
|
||||||
return {
|
|
||||||
href: urlParsingNode.href,
|
|
||||||
protocol: urlParsingNode.protocol ? urlParsingNode.protocol.replace(/:$/, '') : '',
|
|
||||||
host: urlParsingNode.host,
|
|
||||||
search: urlParsingNode.search ? urlParsingNode.search.replace(/^\?/, '') : '',
|
|
||||||
hash: urlParsingNode.hash ? urlParsingNode.hash.replace(/^#/, '') : '',
|
|
||||||
hostname: urlParsingNode.hostname,
|
|
||||||
port: urlParsingNode.port,
|
|
||||||
pathname: (urlParsingNode.pathname.charAt(0) === '/') ?
|
|
||||||
urlParsingNode.pathname :
|
|
||||||
'/' + urlParsingNode.pathname
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
originUrl = urlResolve(window.location.href);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Determine if a URL shares the same origin as the current location
|
|
||||||
*
|
|
||||||
* @param {String} requestUrl The URL to test
|
|
||||||
* @returns {boolean} True if URL shares the same origin, otherwise false
|
|
||||||
*/
|
|
||||||
module.exports = function urlIsSameOrigin(requestUrl) {
|
|
||||||
var parsed = (utils.isString(requestUrl)) ? urlResolve(requestUrl) : requestUrl;
|
|
||||||
return (parsed.protocol === originUrl.protocol &&
|
|
||||||
parsed.host === originUrl.host);
|
|
||||||
};
|
|
||||||
+23
-28
@@ -43,11 +43,13 @@ function isFormData(val) {
|
|||||||
* @returns {boolean} True if value is a view on an ArrayBuffer, otherwise false
|
* @returns {boolean} True if value is a view on an ArrayBuffer, otherwise false
|
||||||
*/
|
*/
|
||||||
function isArrayBufferView(val) {
|
function isArrayBufferView(val) {
|
||||||
|
var result;
|
||||||
if ((typeof ArrayBuffer !== 'undefined') && (ArrayBuffer.isView)) {
|
if ((typeof ArrayBuffer !== 'undefined') && (ArrayBuffer.isView)) {
|
||||||
return ArrayBuffer.isView(val);
|
result = ArrayBuffer.isView(val);
|
||||||
} else {
|
} else {
|
||||||
return (val) && (val.buffer) && (val.buffer instanceof ArrayBuffer);
|
result = (val) && (val.buffer) && (val.buffer instanceof ArrayBuffer);
|
||||||
}
|
}
|
||||||
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -130,16 +132,6 @@ function trim(str) {
|
|||||||
return str.replace(/^\s*/, '').replace(/\s*$/, '');
|
return str.replace(/^\s*/, '').replace(/\s*$/, '');
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Determine if a value is an Arguments object
|
|
||||||
*
|
|
||||||
* @param {Object} val The value to test
|
|
||||||
* @returns {boolean} True if value is an Arguments object, otherwise false
|
|
||||||
*/
|
|
||||||
function isArguments(val) {
|
|
||||||
return toString.call(val) === '[object Arguments]';
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Determine if we're running in a standard browser environment
|
* Determine if we're running in a standard browser environment
|
||||||
*
|
*
|
||||||
@@ -151,7 +143,7 @@ function isArguments(val) {
|
|||||||
* typeof document -> undefined
|
* typeof document -> undefined
|
||||||
*
|
*
|
||||||
* react-native:
|
* react-native:
|
||||||
* typeof document.createelement -> undefined
|
* typeof document.createElement -> undefined
|
||||||
*/
|
*/
|
||||||
function isStandardBrowserEnv() {
|
function isStandardBrowserEnv() {
|
||||||
return (
|
return (
|
||||||
@@ -164,7 +156,7 @@ function isStandardBrowserEnv() {
|
|||||||
/**
|
/**
|
||||||
* Iterate over an Array or an Object invoking a function for each item.
|
* Iterate over an Array or an Object invoking a function for each item.
|
||||||
*
|
*
|
||||||
* If `obj` is an Array or arguments callback will be called passing
|
* If `obj` is an Array callback will be called passing
|
||||||
* the value, index, and complete array for each item.
|
* the value, index, and complete array for each item.
|
||||||
*
|
*
|
||||||
* If 'obj' is an Object callback will be called passing
|
* If 'obj' is an Object callback will be called passing
|
||||||
@@ -179,22 +171,19 @@ function forEach(obj, fn) {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check if obj is array-like
|
|
||||||
var isArrayLike = isArray(obj) || isArguments(obj);
|
|
||||||
|
|
||||||
// Force an array if not already something iterable
|
// Force an array if not already something iterable
|
||||||
if (typeof obj !== 'object' && !isArrayLike) {
|
if (typeof obj !== 'object' && !isArray(obj)) {
|
||||||
|
/*eslint no-param-reassign:0*/
|
||||||
obj = [obj];
|
obj = [obj];
|
||||||
}
|
}
|
||||||
|
|
||||||
// Iterate over array values
|
if (isArray(obj)) {
|
||||||
if (isArrayLike) {
|
// Iterate over array values
|
||||||
for (var i = 0, l = obj.length; i < l; i++) {
|
for (var i = 0, l = obj.length; i < l; i++) {
|
||||||
fn.call(null, obj[i], i, obj);
|
fn.call(null, obj[i], i, obj);
|
||||||
}
|
}
|
||||||
}
|
} else {
|
||||||
// Iterate over object keys
|
// Iterate over object keys
|
||||||
else {
|
|
||||||
for (var key in obj) {
|
for (var key in obj) {
|
||||||
if (obj.hasOwnProperty(key)) {
|
if (obj.hasOwnProperty(key)) {
|
||||||
fn.call(null, obj[key], key, obj);
|
fn.call(null, obj[key], key, obj);
|
||||||
@@ -220,13 +209,19 @@ function forEach(obj, fn) {
|
|||||||
* @param {Object} obj1 Object to merge
|
* @param {Object} obj1 Object to merge
|
||||||
* @returns {Object} Result of all merge properties
|
* @returns {Object} Result of all merge properties
|
||||||
*/
|
*/
|
||||||
function merge(/*obj1, obj2, obj3, ...*/) {
|
function merge(/* obj1, obj2, obj3, ... */) {
|
||||||
var result = {};
|
var result = {};
|
||||||
forEach(arguments, function (obj) {
|
function assignValue(val, key) {
|
||||||
forEach(obj, function (val, key) {
|
if (typeof result[key] === 'object' && typeof val === 'object') {
|
||||||
|
result[key] = merge(result[key], val);
|
||||||
|
} else {
|
||||||
result[key] = val;
|
result[key] = val;
|
||||||
});
|
}
|
||||||
});
|
}
|
||||||
|
|
||||||
|
for (var i = 0, l = arguments.length; i < l; i++) {
|
||||||
|
forEach(arguments[i], assignValue);
|
||||||
|
}
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+7
-2
@@ -1,10 +1,11 @@
|
|||||||
{
|
{
|
||||||
"name": "axios",
|
"name": "axios",
|
||||||
"version": "0.7.0",
|
"version": "0.8.1",
|
||||||
"description": "Promise based HTTP client for the browser and node.js",
|
"description": "Promise based HTTP client for the browser and node.js",
|
||||||
"main": "index.js",
|
"main": "index.js",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"test": "grunt test",
|
"build": "./node_modules/.bin/grunt build",
|
||||||
|
"test": "./node_modules/.bin/grunt test",
|
||||||
"start": "node ./sandbox/server.js",
|
"start": "node ./sandbox/server.js",
|
||||||
"examples": "node ./examples/server.js",
|
"examples": "node ./examples/server.js",
|
||||||
"coveralls": "cat coverage/lcov.info | ./node_modules/coveralls/bin/coveralls.js"
|
"coveralls": "cat coverage/lcov.info | ./node_modules/coveralls/bin/coveralls.js"
|
||||||
@@ -47,6 +48,7 @@
|
|||||||
"karma-jasmine": "0.3.6",
|
"karma-jasmine": "0.3.6",
|
||||||
"karma-jasmine-ajax": "0.1.13",
|
"karma-jasmine-ajax": "0.1.13",
|
||||||
"karma-phantomjs-launcher": "0.2.1",
|
"karma-phantomjs-launcher": "0.2.1",
|
||||||
|
"karma-sinon": "1.0.4",
|
||||||
"karma-sourcemap-loader": "0.3.5",
|
"karma-sourcemap-loader": "0.3.5",
|
||||||
"karma-webpack": "1.7.0",
|
"karma-webpack": "1.7.0",
|
||||||
"load-grunt-tasks": "3.3.0",
|
"load-grunt-tasks": "3.3.0",
|
||||||
@@ -60,5 +62,8 @@
|
|||||||
},
|
},
|
||||||
"typescript": {
|
"typescript": {
|
||||||
"definition": "./axios.d.ts"
|
"definition": "./axios.d.ts"
|
||||||
|
},
|
||||||
|
"dependencies": {
|
||||||
|
"follow-redirects": "0.0.7"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,43 @@
|
|||||||
|
var axios = require('../../index');
|
||||||
|
|
||||||
|
module.exports = function setupBasicAuthTest() {
|
||||||
|
beforeEach(function () {
|
||||||
|
jasmine.Ajax.install();
|
||||||
|
});
|
||||||
|
|
||||||
|
afterEach(function () {
|
||||||
|
jasmine.Ajax.uninstall();
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should accept HTTP Basic auth with username/password', function (done) {
|
||||||
|
axios({
|
||||||
|
url: '/foo',
|
||||||
|
auth: {
|
||||||
|
username: 'Aladdin',
|
||||||
|
password: 'open sesame'
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
setTimeout(function () {
|
||||||
|
var request = jasmine.Ajax.requests.mostRecent();
|
||||||
|
|
||||||
|
expect(request.requestHeaders['Authorization']).toEqual('Basic QWxhZGRpbjpvcGVuIHNlc2FtZQ==');
|
||||||
|
done();
|
||||||
|
}, 0);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should fail to encode HTTP Basic auth credentials with non-Latin1 characters', function (done) {
|
||||||
|
axios({
|
||||||
|
url: '/foo',
|
||||||
|
auth: {
|
||||||
|
username: 'Aladßç£☃din',
|
||||||
|
password: 'open sesame'
|
||||||
|
}
|
||||||
|
}).then(function(response) {
|
||||||
|
done(new Error('Should not succeed to make a HTTP Basic auth request with non-latin1 chars in credentials.'));
|
||||||
|
}).catch(function(error) {
|
||||||
|
expect(error.message).toEqual('INVALID_CHARACTER_ERR: DOM Exception 5');
|
||||||
|
done();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
};
|
||||||
+29
-1
@@ -1,6 +1,6 @@
|
|||||||
var axios = require('../../index');
|
var axios = require('../../index');
|
||||||
|
|
||||||
describe('api', function () {
|
describe('static api', function () {
|
||||||
it('should have request method helpers', function () {
|
it('should have request method helpers', function () {
|
||||||
expect(typeof axios.get).toEqual('function');
|
expect(typeof axios.get).toEqual('function');
|
||||||
expect(typeof axios.head).toEqual('function');
|
expect(typeof axios.head).toEqual('function');
|
||||||
@@ -22,8 +22,36 @@ describe('api', function () {
|
|||||||
expect(typeof axios.defaults.headers).toEqual('object');
|
expect(typeof axios.defaults.headers).toEqual('object');
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('should have interceptors', function () {
|
||||||
|
expect(typeof axios.interceptors.request).toEqual('object');
|
||||||
|
expect(typeof axios.interceptors.response).toEqual('object');
|
||||||
|
});
|
||||||
|
|
||||||
it('should have all/spread helpers', function () {
|
it('should have all/spread helpers', function () {
|
||||||
expect(typeof axios.all).toEqual('function');
|
expect(typeof axios.all).toEqual('function');
|
||||||
expect(typeof axios.spread).toEqual('function');
|
expect(typeof axios.spread).toEqual('function');
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('should have factory method', function () {
|
||||||
|
expect(typeof axios.create).toEqual('function');
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('instance api', function () {
|
||||||
|
var instance = axios.create();
|
||||||
|
|
||||||
|
it('should have request methods', function () {
|
||||||
|
expect(typeof instance.request).toEqual('function');
|
||||||
|
expect(typeof instance.get).toEqual('function');
|
||||||
|
expect(typeof instance.head).toEqual('function');
|
||||||
|
expect(typeof instance.delete).toEqual('function');
|
||||||
|
expect(typeof instance.post).toEqual('function');
|
||||||
|
expect(typeof instance.put).toEqual('function');
|
||||||
|
expect(typeof instance.patch).toEqual('function');
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should have interceptors', function () {
|
||||||
|
expect(typeof instance.interceptors.request).toEqual('object');
|
||||||
|
expect(typeof instance.interceptors.response).toEqual('object');
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -0,0 +1,5 @@
|
|||||||
|
var setupBasicAuthTest = require('./__setupBasicAuthTest');
|
||||||
|
|
||||||
|
describe('basicAuth without btoa polyfill', function () {
|
||||||
|
setupBasicAuthTest();
|
||||||
|
});
|
||||||
@@ -0,0 +1,21 @@
|
|||||||
|
var setupBasicAuthTest = require('./__setupBasicAuthTest');
|
||||||
|
var window_btoa;
|
||||||
|
|
||||||
|
describe('basicAuth with btoa polyfill', function () {
|
||||||
|
beforeAll(function() {
|
||||||
|
window_btoa = window.btoa;
|
||||||
|
window.btoa = undefined;
|
||||||
|
});
|
||||||
|
|
||||||
|
afterAll(function() {
|
||||||
|
window.btoa = window_btoa;
|
||||||
|
window_btoa = undefined;
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should not have native window.btoa', function () {
|
||||||
|
expect(window.btoa).toEqual(undefined);
|
||||||
|
});
|
||||||
|
|
||||||
|
setupBasicAuthTest();
|
||||||
|
});
|
||||||
|
|
||||||
@@ -1,6 +1,22 @@
|
|||||||
|
var axios = require('../../index');
|
||||||
var defaults = require('../../lib/defaults');
|
var defaults = require('../../lib/defaults');
|
||||||
|
var utils = require('../../lib/utils');
|
||||||
|
|
||||||
describe('defaults', function () {
|
describe('defaults', function () {
|
||||||
|
var __defaults;
|
||||||
|
var XSRF_COOKIE_NAME = 'CUSTOM-XSRF-TOKEN';
|
||||||
|
|
||||||
|
beforeEach(function () {
|
||||||
|
jasmine.Ajax.install();
|
||||||
|
__defaults = axios.defaults;
|
||||||
|
});
|
||||||
|
|
||||||
|
afterEach(function () {
|
||||||
|
jasmine.Ajax.uninstall();
|
||||||
|
axios.defaults = __defaults;
|
||||||
|
document.cookie = XSRF_COOKIE_NAME + '=;expires=' + new Date(Date.now() - 86400000).toGMTString();
|
||||||
|
});
|
||||||
|
|
||||||
it('should transform request json', function () {
|
it('should transform request json', function () {
|
||||||
expect(defaults.transformRequest[0]({foo: 'bar'})).toEqual('{"foo":"bar"}');
|
expect(defaults.transformRequest[0]({foo: 'bar'})).toEqual('{"foo":"bar"}');
|
||||||
});
|
});
|
||||||
@@ -19,5 +35,105 @@ describe('defaults', function () {
|
|||||||
it('should do nothing to response string', function () {
|
it('should do nothing to response string', function () {
|
||||||
expect(defaults.transformResponse[0]('foo=bar')).toEqual('foo=bar');
|
expect(defaults.transformResponse[0]('foo=bar')).toEqual('foo=bar');
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('should use global defaults config', function (done) {
|
||||||
|
var request;
|
||||||
|
|
||||||
|
axios({ url: '/foo' });
|
||||||
|
|
||||||
|
setTimeout(function () {
|
||||||
|
request = jasmine.Ajax.requests.mostRecent();
|
||||||
|
|
||||||
|
expect(request.url).toBe('/foo');
|
||||||
|
done();
|
||||||
|
}, 0);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should use modified defaults config', function (done) {
|
||||||
|
var request;
|
||||||
|
axios.defaults.baseURL = 'http://example.com/';
|
||||||
|
|
||||||
|
axios({ url: '/foo' });
|
||||||
|
|
||||||
|
setTimeout(function () {
|
||||||
|
request = jasmine.Ajax.requests.mostRecent();
|
||||||
|
|
||||||
|
expect(request.url).toBe('http://example.com/foo');
|
||||||
|
done();
|
||||||
|
}, 0);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should use request config', function (done) {
|
||||||
|
var request;
|
||||||
|
|
||||||
|
axios({
|
||||||
|
url: '/foo',
|
||||||
|
baseURL: 'http://www.example.com'
|
||||||
|
});
|
||||||
|
|
||||||
|
setTimeout(function () {
|
||||||
|
request = jasmine.Ajax.requests.mostRecent();
|
||||||
|
|
||||||
|
expect(request.url).toBe('http://www.example.com/foo');
|
||||||
|
done();
|
||||||
|
}, 0);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should use default config for custom instance', function (done) {
|
||||||
|
var request;
|
||||||
|
var instance = axios.create({
|
||||||
|
xsrfCookieName: XSRF_COOKIE_NAME,
|
||||||
|
xsrfHeaderName: 'X-CUSTOM-XSRF-TOKEN'
|
||||||
|
});
|
||||||
|
document.cookie = instance.defaults.xsrfCookieName + '=foobarbaz';
|
||||||
|
|
||||||
|
instance.get('/foo');
|
||||||
|
|
||||||
|
setTimeout(function () {
|
||||||
|
request = jasmine.Ajax.requests.mostRecent();
|
||||||
|
|
||||||
|
expect(request.requestHeaders[instance.defaults.xsrfHeaderName]).toEqual('foobarbaz');
|
||||||
|
done();
|
||||||
|
}, 0);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should use header config', function (done) {
|
||||||
|
var request;
|
||||||
|
var instance = axios.create({
|
||||||
|
headers: {
|
||||||
|
common: {
|
||||||
|
'X-COMMON-HEADER': 'commonHeaderValue'
|
||||||
|
},
|
||||||
|
get: {
|
||||||
|
'X-GET-HEADER': 'getHeaderValue'
|
||||||
|
},
|
||||||
|
post: {
|
||||||
|
'X-POST-HEADER': 'postHeaderValue'
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
instance.get('/foo', {
|
||||||
|
headers: {
|
||||||
|
'X-FOO-HEADER': 'fooHeaderValue',
|
||||||
|
'X-BAR-HEADER': 'barHeaderValue'
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
setTimeout(function () {
|
||||||
|
request = jasmine.Ajax.requests.mostRecent();
|
||||||
|
|
||||||
|
expect(request.requestHeaders).toEqual(
|
||||||
|
utils.merge(defaults.headers.common, {
|
||||||
|
'X-COMMON-HEADER': 'commonHeaderValue',
|
||||||
|
'X-GET-HEADER': 'getHeaderValue',
|
||||||
|
'X-FOO-HEADER': 'fooHeaderValue',
|
||||||
|
'X-BAR-HEADER': 'barHeaderValue'
|
||||||
|
})
|
||||||
|
);
|
||||||
|
done();
|
||||||
|
}, 0);
|
||||||
|
});
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,12 @@
|
|||||||
|
var bind = require('../../../lib/helpers/bind');
|
||||||
|
|
||||||
|
describe('bind', function () {
|
||||||
|
it('should bind an object to a function', function () {
|
||||||
|
var o = { val: 123 };
|
||||||
|
var f = bind(function (num) {
|
||||||
|
return this.val * num;
|
||||||
|
}, o);
|
||||||
|
|
||||||
|
expect(f(2)).toEqual(246);
|
||||||
|
});
|
||||||
|
});
|
||||||
@@ -0,0 +1,27 @@
|
|||||||
|
var __btoa = require('../../../lib/helpers/btoa');
|
||||||
|
|
||||||
|
describe('btoa polyfill', function () {
|
||||||
|
it('should behave the same as native window.btoa', function () {
|
||||||
|
var data = 'Hello, world';
|
||||||
|
expect(__btoa(data)).toEqual(window.btoa(data));
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should throw an error if char is out of range 0xFF', function () {
|
||||||
|
var err1, err2;
|
||||||
|
var data = 'I ♡ Unicode!';
|
||||||
|
|
||||||
|
try {
|
||||||
|
window.btoa(data);
|
||||||
|
} catch (e) {
|
||||||
|
err1 = e;
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
__btoa(data);
|
||||||
|
} catch (e) {
|
||||||
|
err2 = e;
|
||||||
|
}
|
||||||
|
|
||||||
|
expect(err1.message).toEqual(err2.message);
|
||||||
|
});
|
||||||
|
});
|
||||||
@@ -1,18 +1,18 @@
|
|||||||
var buildUrl = require('../../../lib/helpers/buildUrl');
|
var buildURL = require('../../../lib/helpers/buildURL');
|
||||||
|
|
||||||
describe('helpers::buildUrl', function () {
|
describe('helpers::buildURL', function () {
|
||||||
it('should support null params', function () {
|
it('should support null params', function () {
|
||||||
expect(buildUrl('/foo')).toEqual('/foo');
|
expect(buildURL('/foo')).toEqual('/foo');
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should support params', function () {
|
it('should support params', function () {
|
||||||
expect(buildUrl('/foo', {
|
expect(buildURL('/foo', {
|
||||||
foo: 'bar'
|
foo: 'bar'
|
||||||
})).toEqual('/foo?foo=bar');
|
})).toEqual('/foo?foo=bar');
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should support object params', function () {
|
it('should support object params', function () {
|
||||||
expect(buildUrl('/foo', {
|
expect(buildURL('/foo', {
|
||||||
foo: {
|
foo: {
|
||||||
bar: 'baz'
|
bar: 'baz'
|
||||||
}
|
}
|
||||||
@@ -22,35 +22,45 @@ describe('helpers::buildUrl', function () {
|
|||||||
it('should support date params', function () {
|
it('should support date params', function () {
|
||||||
var date = new Date();
|
var date = new Date();
|
||||||
|
|
||||||
expect(buildUrl('/foo', {
|
expect(buildURL('/foo', {
|
||||||
date: date
|
date: date
|
||||||
})).toEqual('/foo?date=' + date.toISOString());
|
})).toEqual('/foo?date=' + date.toISOString());
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should support array params', function () {
|
it('should support array params', function () {
|
||||||
expect(buildUrl('/foo', {
|
expect(buildURL('/foo', {
|
||||||
foo: ['bar', 'baz']
|
foo: ['bar', 'baz']
|
||||||
})).toEqual('/foo?foo[]=bar&foo[]=baz');
|
})).toEqual('/foo?foo[]=bar&foo[]=baz');
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should support special char params', function () {
|
it('should support special char params', function () {
|
||||||
expect(buildUrl('/foo', {
|
expect(buildURL('/foo', {
|
||||||
foo: '@:$, '
|
foo: '@:$, '
|
||||||
})).toEqual('/foo?foo=@:$,+');
|
})).toEqual('/foo?foo=@:$,+');
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should support existing params', function () {
|
it('should support existing params', function () {
|
||||||
expect(buildUrl('/foo?foo=bar', {
|
expect(buildURL('/foo?foo=bar', {
|
||||||
bar: 'baz'
|
bar: 'baz'
|
||||||
})).toEqual('/foo?foo=bar&bar=baz');
|
})).toEqual('/foo?foo=bar&bar=baz');
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should support "length" parameter', function () {
|
it('should support "length" parameter', function () {
|
||||||
expect(buildUrl('/foo', {
|
expect(buildURL('/foo', {
|
||||||
query: 'bar',
|
query: 'bar',
|
||||||
start: 0,
|
start: 0,
|
||||||
length: 5
|
length: 5
|
||||||
})).toEqual('/foo?query=bar&start=0&length=5');
|
})).toEqual('/foo?query=bar&start=0&length=5');
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('should use serializer if provided', function () {
|
||||||
|
serializer = sinon.stub();
|
||||||
|
params = {foo: 'bar'};
|
||||||
|
serializer.returns('foo=bar');
|
||||||
|
expect(buildURL('/foo', params, serializer)).toEqual('/foo?foo=bar');
|
||||||
|
expect(serializer.calledOnce).toBe(true);
|
||||||
|
expect(serializer.calledWith(params)).toBe(true);
|
||||||
|
})
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
@@ -0,0 +1,15 @@
|
|||||||
|
var combineURLs = require('../../../lib/helpers/combineURLs');
|
||||||
|
|
||||||
|
describe('helpers::combineURLs', function () {
|
||||||
|
it('should combine URLs', function () {
|
||||||
|
expect(combineURLs('https://api.github.com', '/users')).toBe('https://api.github.com/users');
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should remove duplicate slashes', function () {
|
||||||
|
expect(combineURLs('https://api.github.com/', '/users')).toBe('https://api.github.com/users');
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should insert missing slash', function () {
|
||||||
|
expect(combineURLs('https://api.github.com', 'users')).toBe('https://api.github.com/users');
|
||||||
|
});
|
||||||
|
});
|
||||||
@@ -0,0 +1,23 @@
|
|||||||
|
var isAbsoluteURL = require('../../../lib/helpers/isAbsoluteURL');
|
||||||
|
|
||||||
|
describe('helpers::isAbsoluteURL', function () {
|
||||||
|
it('should return true if URL begins with valid scheme name', function () {
|
||||||
|
expect(isAbsoluteURL('https://api.github.com/users')).toBe(true);
|
||||||
|
expect(isAbsoluteURL('custom-scheme-v1.0://example.com/')).toBe(true);
|
||||||
|
expect(isAbsoluteURL('HTTP://example.com/')).toBe(true);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should return false if URL begins with invalid scheme name', function () {
|
||||||
|
expect(isAbsoluteURL('123://example.com/')).toBe(false);
|
||||||
|
expect(isAbsoluteURL('!valid://example.com/')).toBe(false);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should return true if URL is protocol-relative', function () {
|
||||||
|
expect(isAbsoluteURL('//example.com/')).toBe(true);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should return false if URL is relative', function () {
|
||||||
|
expect(isAbsoluteURL('/foo')).toBe(false);
|
||||||
|
expect(isAbsoluteURL('foo')).toBe(false);
|
||||||
|
});
|
||||||
|
});
|
||||||
@@ -0,0 +1,11 @@
|
|||||||
|
var isURLSameOrigin = require('../../../lib/helpers/isURLSameOrigin');
|
||||||
|
|
||||||
|
describe('helpers::isURLSameOrigin', function () {
|
||||||
|
it('should detect same origin', function () {
|
||||||
|
expect(isURLSameOrigin(window.location.href)).toEqual(true);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should detect different origin', function () {
|
||||||
|
expect(isURLSameOrigin('https://github.com/mzabriskie/axios')).toEqual(false);
|
||||||
|
});
|
||||||
|
});
|
||||||
@@ -1,11 +0,0 @@
|
|||||||
var urlIsSameOrigin = require('../../../lib/helpers/urlIsSameOrigin');
|
|
||||||
|
|
||||||
describe('helpers::urlIsSameOrigin', function () {
|
|
||||||
it('should detect same origin', function () {
|
|
||||||
expect(urlIsSameOrigin(window.location.href)).toEqual(true);
|
|
||||||
});
|
|
||||||
|
|
||||||
it('should detect different origin', function () {
|
|
||||||
expect(urlIsSameOrigin('https://github.com/mzabriskie/axios')).toEqual(false);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
@@ -0,0 +1,75 @@
|
|||||||
|
var axios = require('../../index');
|
||||||
|
|
||||||
|
describe('instance', function () {
|
||||||
|
beforeEach(function () {
|
||||||
|
jasmine.Ajax.install();
|
||||||
|
});
|
||||||
|
|
||||||
|
afterEach(function () {
|
||||||
|
jasmine.Ajax.uninstall();
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should make an http request', function (done) {
|
||||||
|
var instance = axios.create();
|
||||||
|
|
||||||
|
instance.request({
|
||||||
|
url: '/foo'
|
||||||
|
});
|
||||||
|
|
||||||
|
setTimeout(function () {
|
||||||
|
request = jasmine.Ajax.requests.mostRecent();
|
||||||
|
|
||||||
|
expect(request.url).toBe('/foo');
|
||||||
|
done();
|
||||||
|
}, 0);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should use instance options', function (done) {
|
||||||
|
var instance = axios.create({ timeout: 1000 });
|
||||||
|
|
||||||
|
instance.request({
|
||||||
|
url: '/foo'
|
||||||
|
});
|
||||||
|
|
||||||
|
setTimeout(function () {
|
||||||
|
request = jasmine.Ajax.requests.mostRecent();
|
||||||
|
|
||||||
|
expect(request.timeout).toBe(1000);
|
||||||
|
done();
|
||||||
|
}, 0);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should have interceptors on the instance', function (done) {
|
||||||
|
axios.interceptors.request.use(function (config) {
|
||||||
|
config.foo = true;
|
||||||
|
return config;
|
||||||
|
});
|
||||||
|
|
||||||
|
var instance = axios.create();
|
||||||
|
instance.interceptors.request.use(function (config) {
|
||||||
|
config.bar = true;
|
||||||
|
return config;
|
||||||
|
});
|
||||||
|
|
||||||
|
var response;
|
||||||
|
instance.request({
|
||||||
|
url: '/foo'
|
||||||
|
}).then(function (res) {
|
||||||
|
response = res;
|
||||||
|
});
|
||||||
|
|
||||||
|
setTimeout(function () {
|
||||||
|
request = jasmine.Ajax.requests.mostRecent();
|
||||||
|
|
||||||
|
request.respondWith({
|
||||||
|
status: 200
|
||||||
|
});
|
||||||
|
|
||||||
|
setTimeout(function () {
|
||||||
|
expect(response.config.foo).toEqual(undefined);
|
||||||
|
expect(response.config.bar).toEqual(true);
|
||||||
|
done();
|
||||||
|
});
|
||||||
|
}, 0);
|
||||||
|
});
|
||||||
|
});
|
||||||
@@ -78,4 +78,42 @@ describe('options', function () {
|
|||||||
done();
|
done();
|
||||||
}, 0);
|
}, 0);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('should accept base URL', function (done) {
|
||||||
|
var request;
|
||||||
|
|
||||||
|
const instance = axios.create({
|
||||||
|
baseURL: 'http://test.com/'
|
||||||
|
});
|
||||||
|
|
||||||
|
instance.request({
|
||||||
|
url: '/foo'
|
||||||
|
});
|
||||||
|
|
||||||
|
setTimeout(function () {
|
||||||
|
request = jasmine.Ajax.requests.mostRecent();
|
||||||
|
|
||||||
|
expect(request.url).toBe('http://test.com/foo');
|
||||||
|
done();
|
||||||
|
}, 0);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should ignore base URL if request URL is absolute', function (done) {
|
||||||
|
var request;
|
||||||
|
|
||||||
|
const instance = axios.create({
|
||||||
|
baseURL: 'http://someurl.com/'
|
||||||
|
});
|
||||||
|
|
||||||
|
instance.request({
|
||||||
|
url: 'http://someotherurl.com/'
|
||||||
|
});
|
||||||
|
|
||||||
|
setTimeout(function () {
|
||||||
|
request = jasmine.Ajax.requests.mostRecent();
|
||||||
|
|
||||||
|
expect(request.url).toBe('http://someotherurl.com/');
|
||||||
|
done();
|
||||||
|
}, 0);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -54,6 +54,41 @@ describe('requests', function () {
|
|||||||
}, 0);
|
}, 0);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('should make cross domian http request', function (done) {
|
||||||
|
var request, response;
|
||||||
|
|
||||||
|
axios({
|
||||||
|
method: 'post',
|
||||||
|
url: 'www.someurl.com/foo',
|
||||||
|
xDomain: true
|
||||||
|
}).then(function(res){
|
||||||
|
response = res;
|
||||||
|
});
|
||||||
|
|
||||||
|
setTimeout(function () {
|
||||||
|
request = jasmine.Ajax.requests.mostRecent();
|
||||||
|
request.respondWith({
|
||||||
|
status: 200,
|
||||||
|
statusText: 'OK',
|
||||||
|
responseText: '{"foo": "bar"}',
|
||||||
|
headers: {
|
||||||
|
'Content-Type': 'application/json'
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
setTimeout(function () {
|
||||||
|
expect(response.data.foo).toEqual('bar');
|
||||||
|
expect(response.status).toEqual(200);
|
||||||
|
expect(response.statusText).toEqual('OK');
|
||||||
|
expect(response.headers['content-type']).toEqual('application/json');
|
||||||
|
done();
|
||||||
|
}, 0);
|
||||||
|
|
||||||
|
}, 0);
|
||||||
|
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
it('should supply correct response', function (done) {
|
it('should supply correct response', function (done) {
|
||||||
var request, response;
|
var request, response;
|
||||||
|
|
||||||
|
|||||||
@@ -11,18 +11,6 @@ describe('utils::forEach', function () {
|
|||||||
expect(sum).toEqual(15);
|
expect(sum).toEqual(15);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should loop over arguments', function () {
|
|
||||||
var sum = 0;
|
|
||||||
|
|
||||||
(function () {
|
|
||||||
forEach(arguments, function (val) {
|
|
||||||
sum += val;
|
|
||||||
});
|
|
||||||
})(1, 2, 3, 4, 5);
|
|
||||||
|
|
||||||
expect(sum).toEqual(15);
|
|
||||||
});
|
|
||||||
|
|
||||||
it('should loop over object keys', function () {
|
it('should loop over object keys', function () {
|
||||||
var keys = '';
|
var keys = '';
|
||||||
var vals = 0;
|
var vals = 0;
|
||||||
@@ -61,4 +49,3 @@ describe('utils::forEach', function () {
|
|||||||
expect(count).toEqual(1);
|
expect(count).toEqual(1);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@@ -23,5 +23,20 @@ describe('utils::merge', function () {
|
|||||||
expect(d.foo).toEqual(789);
|
expect(d.foo).toEqual(789);
|
||||||
expect(d.bar).toEqual(456);
|
expect(d.bar).toEqual(456);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('should merge recursively', function () {
|
||||||
|
var a = {foo: {bar: 123}};
|
||||||
|
var b = {foo: {baz: 456}, bar: {qux: 789}};
|
||||||
|
|
||||||
|
expect(merge(a, b)).toEqual({
|
||||||
|
foo: {
|
||||||
|
bar: 123,
|
||||||
|
baz: 456
|
||||||
|
},
|
||||||
|
bar: {
|
||||||
|
qux: 789
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@@ -40,4 +40,37 @@ describe('xsrf', function () {
|
|||||||
done();
|
done();
|
||||||
}, 0);
|
}, 0);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('should not set xsrf header for cross origin', function (done) {
|
||||||
|
var request;
|
||||||
|
document.cookie = axios.defaults.xsrfCookieName + '=12345';
|
||||||
|
|
||||||
|
axios({
|
||||||
|
url: 'http://example.com/'
|
||||||
|
});
|
||||||
|
|
||||||
|
setTimeout(function () {
|
||||||
|
request = jasmine.Ajax.requests.mostRecent();
|
||||||
|
|
||||||
|
expect(request.requestHeaders[axios.defaults.xsrfHeaderName]).toEqual(undefined);
|
||||||
|
done();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should set xsrf header for cross origin when using withCredentials', function (done) {
|
||||||
|
var request;
|
||||||
|
document.cookie = axios.defaults.xsrfCookieName + '=12345';
|
||||||
|
|
||||||
|
axios({
|
||||||
|
url: 'http://example.com/',
|
||||||
|
withCredentials: true
|
||||||
|
});
|
||||||
|
|
||||||
|
setTimeout(function () {
|
||||||
|
request = jasmine.Ajax.requests.mostRecent();
|
||||||
|
|
||||||
|
expect(request.requestHeaders[axios.defaults.xsrfHeaderName]).toEqual('12345');
|
||||||
|
done();
|
||||||
|
});
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
+63
-15
@@ -4,11 +4,11 @@ import axios = require('axios');
|
|||||||
|
|
||||||
axios.get('/user?ID=12345')
|
axios.get('/user?ID=12345')
|
||||||
.then(function (response) {
|
.then(function (response) {
|
||||||
console.log(response);
|
console.log(response);
|
||||||
})
|
})
|
||||||
.catch(function (response) {
|
.catch(function (response) {
|
||||||
console.log(response);
|
console.log(response);
|
||||||
});
|
});
|
||||||
|
|
||||||
axios.get('/user', {
|
axios.get('/user', {
|
||||||
params: {
|
params: {
|
||||||
@@ -96,16 +96,64 @@ axios({
|
|||||||
});
|
});
|
||||||
|
|
||||||
axios({
|
axios({
|
||||||
url: "hi",
|
url: "hi",
|
||||||
headers: {'X-Requested-With': 'XMLHttpRequest'},
|
headers: {'X-Requested-With': 'XMLHttpRequest'},
|
||||||
|
params: {
|
||||||
|
ID: 12345
|
||||||
|
},
|
||||||
|
data: {
|
||||||
|
firstName: 'Fred'
|
||||||
|
},
|
||||||
|
withCredentials: false, // default
|
||||||
|
responseType: 'json', // default
|
||||||
|
xsrfCookieName: 'XSRF-TOKEN', // default
|
||||||
|
xsrfHeaderName: 'X-XSRF-TOKEN' // default
|
||||||
|
});
|
||||||
|
|
||||||
|
var instance = axios.create();
|
||||||
|
|
||||||
|
axios.create({
|
||||||
|
transformRequest: (data) => {
|
||||||
|
return data.doSomething();
|
||||||
|
},
|
||||||
|
transformResponse: (data) => {
|
||||||
|
return data.doSomethingElse();
|
||||||
|
},
|
||||||
|
headers: {'X-Requested-With': 'XMLHttpRequest'},
|
||||||
|
timeout: 1000,
|
||||||
|
withCredentials: false, // default
|
||||||
|
responseType: 'json', // default
|
||||||
|
xsrfCookieName: 'XSRF-TOKEN', // default
|
||||||
|
xsrfHeaderName: 'X-XSRF-TOKEN' // default
|
||||||
|
});
|
||||||
|
|
||||||
|
instance.request({
|
||||||
|
method: 'get',
|
||||||
|
url: '/user/12345'
|
||||||
|
})
|
||||||
|
.then(function (response) {
|
||||||
|
console.log(response);
|
||||||
|
})
|
||||||
|
.catch(function (response) {
|
||||||
|
console.log(response);
|
||||||
|
});
|
||||||
|
|
||||||
|
instance.get('/user?ID=12345')
|
||||||
|
.then(function (response) {
|
||||||
|
console.log(response);
|
||||||
|
})
|
||||||
|
.catch(function (response) {
|
||||||
|
console.log(response);
|
||||||
|
});
|
||||||
|
|
||||||
|
instance.get('/user', {
|
||||||
params: {
|
params: {
|
||||||
ID: 12345
|
ID: 12345
|
||||||
},
|
}
|
||||||
data: {
|
})
|
||||||
firstName: 'Fred'
|
.then(function (response) {
|
||||||
},
|
console.log(response);
|
||||||
withCredentials: false, // default
|
})
|
||||||
responseType: 'json', // default
|
.catch(function (response) {
|
||||||
xsrfCookieName: 'XSRF-TOKEN', // default
|
console.log(response);
|
||||||
xsrfHeaderName: 'X-XSRF-TOKEN' // default
|
});
|
||||||
});
|
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
var axios = require('../../../index');
|
var axios = require('../../../index');
|
||||||
var http = require('http');
|
var http = require('http');
|
||||||
|
var zlib = require('zlib');
|
||||||
var server;
|
var server;
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
@@ -27,6 +28,29 @@ module.exports = {
|
|||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
|
||||||
|
testTransparentGunzip: function (test) {
|
||||||
|
var data = {
|
||||||
|
firstName: 'Fred',
|
||||||
|
lastName: 'Flintstone',
|
||||||
|
emailAddr: 'fred@example.com'
|
||||||
|
};
|
||||||
|
|
||||||
|
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-Encoding', 'gzip');
|
||||||
|
res.end(zipped);
|
||||||
|
}).listen(4444, function () {
|
||||||
|
axios.get('http://localhost:4444/').then(function (res) {
|
||||||
|
test.deepEqual(res.data, data);
|
||||||
|
test.done();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
});
|
||||||
|
},
|
||||||
|
|
||||||
testUTF8: function (test) {
|
testUTF8: function (test) {
|
||||||
var str = Array(100000).join('ж');
|
var str = Array(100000).join('ж');
|
||||||
|
|
||||||
|
|||||||
@@ -12,6 +12,9 @@ function generateConfig(name) {
|
|||||||
library: 'axios',
|
library: 'axios',
|
||||||
libraryTarget: 'umd'
|
libraryTarget: 'umd'
|
||||||
},
|
},
|
||||||
|
node: {
|
||||||
|
process: false
|
||||||
|
},
|
||||||
externals: [
|
externals: [
|
||||||
{
|
{
|
||||||
'./adapters/http': 'var undefined'
|
'./adapters/http': 'var undefined'
|
||||||
|
|||||||
Reference in New Issue
Block a user