* 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>
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;
* 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
* The timeoutErrorMessage property in config not work with Node.js (#3580)
* Adding "should respect the timeoutErrorMessage property" test case
Co-authored-by: Will Loo <duibu05@126.com>
* The timeoutErrorMessage property in config not work with Node.js (#3580)
* Fixing The timeoutErrorMessage property in config not work with Node.js (#3580)
* Updating http adapter
* Adding reject config.timeoutErrorMessage when setup
Co-authored-by: Will Loo <duibu05@126.com>
* Fixing The timeoutErrorMessage property in config not work with Node.js (#3580)
* Fixing The timeoutErrorMessage property in config not work with Node.js (#3580)
* Update http adapter
* Make changes as suggested after code review
Co-authored-by: Will Loo <duibu05@126.com>
Co-authored-by: Jay <jasonsaayman@gmail.com>
* Adding request body length validation on HTTP adapter
* Removing error code assertion on HTTP's body length support test
* Removed due to the error being thrown by axios itself now, instead of follow-redirects
Co-authored-by: Jay <jasonsaayman@gmail.com>
* 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>
* Distinguish request and response data types
* Fix Axios headers type
`axios.headers` is not of the same type as `request.headers`, so a new type
`AxiosDefaults` was introduced
* Replace grunt-ts with dtslint
This asserts that the type definitions are valid in the specified TypeScript
version and above. This is the same tool that is used by DefinitelyTyped.
* Remove grunt-ts
* Restore typescript dependency
* Fix missing semicolons
Co-authored-by: Claas Augner <github@caugner.de>
Co-authored-by: Jay <jasonsaayman@gmail.com>
* 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>
* Caseless header comparing in HTTP adapter.
It was adding User-Agent and removing Authorization, but only when
existing headers had the exact right casing. Node uses caseless logic
when managing headers.
This was causing some requests to have `User-Agent` appended to the
headers object and overriding provided agent strings.
Also included is an update to not override the `Content-Length` if it
was already defined in the options. It can be desirable to manually
specify a content length that does not match the data on hand.
Especially for testing.
* Fix eslint error
* fixup: update state UA logic
Play nice with https://github.com/axios/axios/pull/3703
Co-authored-by: Jay <jasonsaayman@gmail.com>
This requires TypeScript users to explicitly define the type of the data they
are consuming.
Before this, data was `any` by default. This means TypeScript consumers didn’t
get type safety if they forgot to specify the type.
Technically this is a breaking change for TypeScript users, as this will report
errors if they forgot to specifiy the response type. The simplest workaround
would be to explicitly set the response type to `any`, so it’s not breaking
much.
The `unknown` type is probably a slightly better fit, but this requires
TypeScript ^3.
`data` is still `any` in the very specific use case mentioned in
https://github.com/microsoft/TypeScript/issues/38969
Co-authored-by: Jay <jasonsaayman@gmail.com>
* Improved type-safety for AxiosRequestConfig
- AxiosRequestConfig is now a generic type whose template corresponds to data
Signed-off-by: Carlos Chida <carlos.chida@starchitecture.eu>
* Fixed tests
- TS tests now match the behaviour described in the PR
Signed-off-by: Carlos Chida <carlos.chida@starchitecture.eu>
Co-authored-by: Jay <jasonsaayman@gmail.com>
* 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>
* 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;
* 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);
* Adding ability to omit User-Agent header
* Update line to be more compact
* Add unit tests for user-agent cases
Co-authored-by: Jay <jasonsaayman@gmail.com>
- Tests for transformResponse
- Remove eslint error by renaming the var
- Test that there data a length to avoid JSON.parse headache
- Use `util.isString()` over `typeof`
Co-authored-by: Jay <jasonsaayman@gmail.com>
* Fixing proxy protocol config when parsed from env vars
* Adding instructions to specify proxy protocol when setting proxy config
* Moved HTTPS proxy config instruction closer to example
* Clear https_proxy env var so as to not impact other tests
* 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>
* 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>
* 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>
* 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>