Commit Graph

178 Commits

Author SHA1 Message Date
sakarit
bdb7d76d40
Adding baseURL to be used in getUri(), also removing question mark trimming since there seems to be no obvious reason for it. (#3737)
Co-authored-by: Jay <jasonsaayman@gmail.com>
2022-03-07 20:09:23 +02:00
João Gabriel Quaresma
195c8e5ff5
Returned error treated when requesting uncommon URL (#3544)
* Fixing error returned when requesting illegal URL

* Adding unit tests http.js

* Fixing error message axios invalid request from browser

* Adding unit tests requests.spec.js

* Adding at utils.js a new method: getProtocol

Co-authored-by: Jay <jasonsaayman@gmail.com>
2022-03-07 19:53:57 +02:00
Dmitriy Mozgovoy
170588f3d7
Refactored project file structure to avoid circular imports; (#4220)
Co-authored-by: Jay <jasonsaayman@gmail.com>
2022-03-07 09:09:43 +02:00
Jay
d660e29c1a
Revert "Fixed isFormData predicate; (#4413)" (#4472)
This reverts commit 73e3bdb883.
2022-02-13 15:47:38 +02:00
Dmitriy Mozgovoy
73e3bdb883
Fixed isFormData predicate; (#4413)
Added support for automatic object serialization to FormData if `Content-Type` is `multipart/form-data`;
Added support for FormData to be overloaded using `config.env.FormData` option;
Added support for FormData in node.js environment through `form-data` package;
2022-02-02 13:48:44 +02:00
Jay
cc86c6c49f
Fix/remove url required (#4426)
* Removed error when url is null as this breaks current use cases for alot of projects

* Removed associated tests that check for the for url to not be empty
2022-01-27 08:39:25 +02:00
Jay
5c5cbdf4ba Removed cancel token request test till debugging on FireFox can be done 2022-01-18 09:24:55 +02:00
Hirotaka Tagawa / wafuwafu13
95792908f0
Adding error handling when missing url (#3791)
* Fixing error message when missing url

* Fixing missing url

* Adding missing url case

* Update Axios.js

* Update requests.spec.js

* Update api.spec.js

* Update api.spec.js

* Update api.spec.js

Co-authored-by: Jay <jasonsaayman@gmail.com>
2021-12-23 10:53:40 +02:00
Ben Carp
99648153ce
toFormData helper function (#3757)
* adding toFormData test

* adding toFormData

Co-authored-by: Jay <jasonsaayman@gmail.com>
2021-12-23 10:21:51 +02:00
Wolfram Kriesing
e6aef5a1c4
(Add tests to) document how multiple inceptors work (#3564)
* Add a group for the multiple-interceptors tests.

The current test contains a lot of details that are worth being tested
separately and also made explicit. This is what is coming with the next changes.

* Fix indentation.

* Make explicit that the test only tests the interception of the fulfilled part.

* Indent.

* Make the test just test a tiny bit, as described.

The more explicit the test, the better we can 1) describe what it does
and use that for the docs to make them understandable 2) have a better
explicit description of the API (in case we want to modify it) and 3) have
a regression test when changing.

* Add a test that explicitly shows that the order of interceptors is as they were added.

* Pull out reusable code, to make the tests more explicitly stating the things they care about.

* Write a test showing that the responses are not merged or anything,
only the last one in the chain is returned.

* Make visible that the interceptors are a chain, one receives its predecessor's data.

* Test what happens when the interceptor throws.

* Refactor, add another group of tests and pull helper function there.

The previous change to also catch in the helper function was not needed
for any of the tests above, so remove it and put it in the describe-block
below where it is needed.
Just trying to write the specific code needed, not more.
Not sure about the impact for failing tests, I am glad about input.
But the main intention here is to have minimal code, explicit tests and
not too much generic code which might break itself eventually.

* Documenting that the following reject-interceptor gets called.

* Documenting how the interceptor chain handles caught rejections.

* Document "multiple interceptors".

I just extracted the test descriptions from the new/modified tests.
And I also learned that I should improve the test descriptions, the
tests are just in a GIVEN-WHEN-THEN structure, so I can also use those
terms better. Will do this next.

* Transfer the better readable descriptions as I changed them in the README back into the tests.

After I had updated the README using the test descriptions I realized how
the test descriptions can be improved, so I did this "moving" the learnings
back into the code.

* Be a bit more explicit, it was not clear when reading, imho.

* Add new lines to be kinda consistent with the rest of the file.

Co-authored-by: Jay <jasonsaayman@gmail.com>
2021-12-22 21:14:52 +02:00
Black-Hole
6fca6a7027
refactor(helpers): optimize the logic of isAxiosError (#3546)
1. add the judgment of null

Co-authored-by: Jay <jasonsaayman@gmail.com>
2021-12-22 21:09:33 +02:00
Jay
76f09afc03
Release/v0.22.0 (#4107)
* fix/Avoid package.json import; (#4041)

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

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

* Feat/export package version constant (#4065)

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

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

* Export package version constant;

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

* Fixed cancelToken leakage;
Added AbortController support;

* Fixed typings;

* Documented `signal` option;

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

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

* Updating CI to run on release branches

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

Refactored `/core/mergeConfig`;

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

* Prepping v0.22.0 for release

* Updated date

Co-authored-by: Dmitriy Mozgovoy <robotshara@gmail.com>
2021-10-01 08:02:13 +02:00
Jay
4091b075f6
Release/0.21.4 (#4025)
* fix json transform when data is pre-stringified (#4020)

* [Updating] incorrect JSON syntax in README.md

* [Releasing] v0.21.4

Co-authored-by: Guillaume FORTAINE <guillaume+github@fortaine.com>
2021-09-06 17:35:06 +02:00
Greg Byrne
cd7ff042b0
Adding HTTP status code to error.toJSON (#2956)
* Adding HTTP status code to error.toJSON (axios#2947)

* Adding Error display div to internal server client.html

Co-authored-by: Jay <jasonsaayman@gmail.com>
2021-09-05 13:45:24 +02:00
Julian Hollmann
83ae3830e4
Correctly add response interceptors to interceptor chain (#4013) 2021-09-04 20:55:38 +02:00
Daniel Lopretto
dbc634cf70
Remove charset in tests (#3807)
* removed charset setting when setting default header

* Remove charset from tests

Co-authored-by: mpark86 <dev.minuk.park@gmail.com>
Co-authored-by: Jay <jasonsaayman@gmail.com>
Co-authored-by: Pilot <timemachine@ctrl-c.club>
2021-05-21 07:51:31 +02:00
Dmitriy Mozgovoy
7821ed2089
Feat/json improvements (#3763)
* Draft

* Added support for primitive types to be converted to JSON if the request Content-Type is 'application/json';
Added throwing SyntaxError if JSON parsing failed and responseType is json;
Added transitional option object;
Added options validator to assert transitional options;
Added transitional option `silentJSONParsing= true` for backward compatibility;
Updated README.md;
Updated typings;

* Fixed isOlderVersion helper;
Fixed typo;
Added validator.spec.js;

* Added forcedJSONParsing transitional option #2791

* `transformData` is now called in the default configuration context if the function context is not specified (for tests compatibility);

* Added `transitional.clarifyTimeoutError` to throw ETIMEDOUT error instead of generic ECONNABORTED on request timeouts;
Added support of onloadend handler if available instead of onreadystatechange;
Added xhr timeout test;
Fixed potential bug of xhr adapter with proper handling timeouts&errors (FakeXMLHTTPRequest failed to handle timeouts);

* Removed unnecessary assertion;
2021-04-19 22:05:48 +02:00
Dmitriy Mozgovoy
5ad6994da3
JSON improvements: throw if JSON parsing failed; number, boolean can be passed directly as payload for encoding to JSON #2613, #61, #907 (#3688)
* Draft

* Added support for primitive types to be converted to JSON if the request Content-Type is 'application/json';
Added throwing SyntaxError if JSON parsing failed and responseType is json;
Added transitional option object;
Added options validator to assert transitional options;
Added transitional option `silentJSONParsing= true` for backward compatibility;
Updated README.md;
Updated typings;

* Fixed isOlderVersion helper;
Fixed typo;
Added validator.spec.js;

* Added forcedJSONParsing transitional option #2791

* `transformData` is now called in the default configuration context if the function context is not specified (for tests compatibility);

* Added `transitional.clarifyTimeoutError` to throw ETIMEDOUT error instead of generic ECONNABORTED on request timeouts;
Added support of onloadend handler if available instead of onreadystatechange;
Added xhr timeout test;
Fixed potential bug of xhr adapter with proper handling timeouts&errors (FakeXMLHTTPRequest failed to handle timeouts);
2021-04-19 18:55:34 +02:00
Sasha Korotkov
62d6256039
issue#2609 | Sasha | predictable axios requests (#2702)
* issue#2609 | Sasha | predictable axios requests

- axios requests are not delayed by pre-emptive promise creation by default
- add options to interceptors api ("synchronous" and "runWhen")
- add documentation and unit tests

* issue#2609 | Sasha | pull request feedback changes

* issue#2609 | Sasha | additional feedback changes

* issue#2609 | Sasha | put back try/catch

* issue#2609 | Sasha | add 2 adapter unit tests

- remove check for requestCancelled

Co-authored-by: ak71845 <alexandre.korotkov@kroger.com>
Co-authored-by: Xianming Zhong <chinesedfan@qq.com>
Co-authored-by: Jay <jasonsaayman@gmail.com>
2021-03-01 11:11:35 +02:00
Jason Kwok
f472e5da5f
Adding a type guard for AxiosError (#2949)
Co-authored-by: Jason Kwok <JasonHK@users.noreply.github.com>
2020-11-03 10:01:07 +02:00
Kevin Kirsche
6d05b96dca
Fix typos (#3309)
Fix typos
2020-10-03 12:25:07 -06:00
Xianming Zhong
fa3673710e
fix axios.delete ignores config.data (#3282)
Co-authored-by: Jay <jasonsaayman@gmail.com>
2020-10-01 09:46:32 +02:00
Allan Cruz
04d45f2091
Fixing requestHeaders.Authorization (#3287) 2020-09-20 10:19:48 +08:00
Tim Gates
e8c6e19141
docs: Fix simple typo, existant -> existent (#3252) 2020-09-12 12:29:35 +08:00
rockcs1992
36f0ad2f98
Replace 'blacklist' with 'blocklist' (#3006) 2020-06-10 13:47:31 -06:00
Xianming Zhong
0d69a79c81
Refactor mergeConfig without utils.deepMerge (#2844)
* Adding failing test

* Fixing #2587 default custom config persisting

* Adding Concat keys and filter duplicates

* Fixed value from CPE

* update for review feedbacks

* no deepMerge

* only merge between plain objects

* fix rename

* always merge config by mergeConfig

* extract function mergeDeepProperties

* refactor mergeConfig with all keys, and add special logic for validateStatus

* add test for resetting headers

* add lots of tests and fix a bug

* should not inherit `data`

* use simple toString

* revert #1845

Co-authored-by: David Tanner <david.tanner@lifeomic.com>
Co-authored-by: Justin Beckwith <justin.beckwith@gmail.com>
2020-06-08 20:52:45 +02:00
Martti Laine
487941663b
Allow unsetting headers by passing null (#382) (#1845)
Co-authored-by: Jay <jasonsaayman@gmail.com>
2020-06-04 20:57:54 +02:00
Jay
f2b478f7ff
Revert "Fixing default transformRequest with buffer pools (#1511)" (#2982)
This reverts commit a9a3b5e22b.
2020-05-27 20:05:26 +02:00
Zac Delventhal
a9a3b5e22b
Fixing default transformRequest with buffer pools (#1511)
* Fixing default transformRequest of TypedArrays with buffer pools

A buffer pool is a large ArrayBuffer of a preset size used with a TypedArray
such as Uint8Array. This can speed up performance when constructing TypedArrays
of unknown sizes, and is a technique used by Node with their Buffers, and
by libraries like dcodeIO/protobuf.js.

Because the ArrayBuffer of such a TypedArray is much longer than the array
itself, using `.buffer` to transform the array before POSTing results in
sending a request with many extraneous empty bytes, which is wastefule and may
result in unexpected behavior.

Using `.slice()` before grabbing the ArrayBuffer fixes the problem by creating
a new TypedArray with a buffer of the expected length.

Signed-off-by: Zac Delventhal <delventhalz@gmail.com>

* Adding test for using default transformRequest with buffer pools

Adds a new test to the default transformRequest, running it on a
Uint8Array with a byte length of 16, but a much larger ArrayBuffer
with a byte length of 256. The transformed array should not include
any extra bytes, and so must have a byte length of just 16.

Signed-off-by: Zac Delventhal <delventhalz@gmail.com>

Co-authored-by: Zac Delventhal <zac@bitwise.io>
Co-authored-by: Jay <jasonsaayman@gmail.com>
2020-05-27 14:42:41 +02:00
David
8a8c534a60
Fixing special char encoding (#1671)
* removing @ character from replacement list since it is a reserved character

* Updating buildURL test to not include the @ character

* Removing console logs

Co-authored-by: Jay <jasonsaayman@gmail.com>
2020-05-27 14:37:39 +02:00
Petr Mares
5effc0827e
Fixing password encoding with special characters in basic authentication (#1492)
* Fixing password encoding with special characters in basic authentication

* Adding test to check if password with non-Latin1 characters pass

Co-authored-by: petr.mares <petr.mares@linecorp.com>
Co-authored-by: Jay <jasonsaayman@gmail.com>
2020-05-26 18:32:03 +02:00
Jay
cbda78552b
Revert "Bug/allow header to contain http verb keys #1252 (#1258)" (#2977)
This reverts commit 920510b3a6.
2020-05-22 21:44:26 +02:00
David Ko
920510b3a6
Bug/allow header to contain http verb keys #1252 (#1258)
* Failing test for #1252

* Only delete header keys that match an HTTP verb if the value is a non-string

Co-authored-by: David Ko <david.ko@pvtmethod.com>
Co-authored-by: Jay <jasonsaayman@gmail.com>
2020-05-22 21:26:10 +02:00
Alan Wang
885ada6d9b
Fixing getting local files (file://) failed (#2470)
* fix issue #2416, #2396

* fix Eslint warn

* Modify judgment conditions

* add unit test

* update unit test

* update unit test
2020-03-23 21:49:38 +08:00
Xianming Zhong
2034c1db7e
Fix tests in browsers (#2748) 2020-02-15 15:54:43 +08:00
Jonathan Sharpe
77f0ae4f61
Fix merging of params (#2656)
* Name function to avoid ESLint func-names warning

* Switch params config to merge list and update tests

* Restore testing of both false and null

* Restore test cases for keys without defaults

* Include test for non-object values that aren't false-y.
2020-02-15 13:36:52 +08:00
Xianming Zhong
c7488c7dd5 Remove unnecessary XSS check introduced by #2451 (#2679)
* Remove unnecessary XSS check introduced by #2451

* Remove test file of `isValidXss`
2020-01-20 09:20:33 -07:00
Angelos Chalaris
1a32ca0601 Remove dependency on is-buffer (#1816)
* Remove dependency on is-buffer from package.json
2019-11-17 22:53:27 -08:00
Yasu Flores
841466416b
Fix XSS logic that matched some valid urls (#2529)
* Fix XSS logic that matched some valid urls, e.g. "/one/?foo=bar", when it shouldn't match those
2019-11-07 18:39:24 -08:00
Felipe Martins
097948698a
Revert "Update Webpack + deps, remove now unnecessary polyfills" (#2479)
* Revert "Update Webpack + deps, remove now unnecessary polyfills (#2410)"

This reverts commit 189b34c45a.

* Fix build (#2496)

* Change syntax to see if build passes

* Test commit

* Test with node 10

* Test adding all browsers in travis

* remove other browsers when running on travis
2019-10-25 11:34:47 -03:00
Yasu Flores
494d817314 Change syntax to see if build passes (#2488)
* Change syntax to see if build passes

* Test commit

* Test with node 10

* Test adding all browsers in travis

* remove other browsers when running on travis
2019-10-25 11:25:53 -03:00
Avindra Goolcharan
189b34c45a Update Webpack + deps, remove now unnecessary polyfills (#2410)
* Update deps

 * handles webpack 1 -> 4 migration

* remove promise helpers from dev files

assume `Promise` is available, or polyfilled by
the consumer

* Remove isArray util. `isArray` has good coverage, even
   in IE9. So lets remove the custom polyfill.

 https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/isArray

also resolves a few lint issues

* Remove trim util

String.protoype.trim has good coverage (including IE9)

https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/Trim

Also, the http adapter already uses the native method.
2019-10-21 15:56:29 -03:00
Yasu Flores
29da6b24db Fix to prevent XSS, throw an error when the URL contains a JS script (#2464)
* Fixes issue where XSS scripts attacks were possible via the URL

* Fix error

* Move throwing error up

* Add specs and make regex cover more xss cases
2019-10-16 07:53:10 -03:00
Wataru
19969b4fbd Fixing Vulnerability A Fortify Scan finds a critical Cross-Site Scrip… (#2451)
* Fixing Vulnerability A Fortify Scan finds a critical Cross-Site Scripting

* use var insted of const
2019-10-08 21:23:34 -03:00
Felipe Martins
c282e7ea8e
Fix cancellation error on build master. #2290 #2207 (#2407) 2019-09-12 23:45:06 -03:00
Rafael Renan Pacheco
a11cdf4683 Fixing custom config options (#2207)
- fixes #2203
2019-09-06 21:40:04 -03:00
DIO
89bd3abe9a Axios create url bug (#2290)
* Fix #2234 

* added spacing --eslint

* added test cases

* removed unexpected cases after updating the code
2019-09-06 12:45:18 -03:00
multicolaure
6fe506fda2 Do not modify config.url when using a relative baseURL (resolves #1628) (#2391)
* Adding tests to show config.url mutation

Because config.url is modified while processing the request
when the baseURL is set,
it is impossible to perform a retry with the provided config object.

Ref #1628

* Fixing url combining without modifying config.url

As config.url is not modified anymore during the request processing.
The request can safely be retried after it failed with the provided
config.

resolves #1628
2019-09-05 12:43:55 -03:00
Anatoly Ryabov
81eaa3db4c Fixing building url with hash mark (#1771)
This commit fix building url with hash map (fragment identifier) when parameters are present: they must not be added after `#`, because client cut everything after `#`
2018-09-04 09:53:57 +02:00
Ayush Gupta
b681e919c4 Adding isAxiosError flag to errors thrown by axios (#1419) 2018-08-20 11:02:23 +02:00