2
0
mirror of https://github.com/tenrok/axios.git synced 2026-05-15 11:59:42 +03:00
Commit Graph

202 Commits

Author SHA1 Message Date
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
Zoran Kokeza 412d3bd607 Adding support for beforeRedirect config option (#3852)
* Adding support for beforeRedirect config option

* Adding tests for beforeRedirect

* Update README.md

Co-authored-by: Prabodh Meshram <prabodh.meshram7@gmail.com>

* fix types

Co-authored-by: Prabodh Meshram <prabodh.meshram7@gmail.com>
Co-authored-by: Jay <jasonsaayman@gmail.com>
2022-03-07 19:46:08 +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
Daniel 1163588aa2 Added errors to be displayed when the query parsing process itself fails. (#3961)
* Adding errors when the query parsing process fails

* Updated error

* Removed unused variables

Co-authored-by: Jay <jasonsaayman@gmail.com>
2022-01-18 18:50:33 +02:00
duibu05 4461761fcb Fixed The timeoutErrorMessage property in config not work with Node.js (fixes #3580) (#3581)
* 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>
2022-01-18 18:40:18 +02:00
Daniel ea0d9c69f7 Adding error handling inside stream end callback (#3967)
* Adding error handling inside end callback  for response streams

* Updating error handling in stream end callback

* Update http.js

Co-authored-by: Jay <jasonsaayman@gmail.com>
2021-12-23 19:28:10 +02:00
Paulo Renato c00c4ddd87 Fixing maxBodyLength enforcement (#3786)
* 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>
2021-12-23 10:19:02 +02:00
Doowonee 55e6577b75 Adding a socket handler for keep TCP connection (#3422)
This is not http keepalive option it is TCP level
which is lower than HTTP.

It will send meanless ack flag packet to server.
so it woudn't be drop TCP connection by server side
like Firewall, Loadbalancer, Nginx etc.

Co-authored-by: Jay <jasonsaayman@gmail.com>
2021-12-22 20:56:14 +02:00
Andrey Pechkurov ebedf6b653 Avoid unnecessary Buffer allocations (#3321) 2021-12-22 20:50:05 +02:00
Kohta Ito c5fe05bdff Adding aborted event handler (#3916)
* Adding test of aborts request

* Adding aborted event handler

* Fixing timing of setting rejected flag

Co-authored-by: Jay <jasonsaayman@gmail.com>
2021-10-29 10:05:01 +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
Dobes Vandermeer 96956e30ba Improve timeout error when timeout is browser default (#3209)
I seems like the browser imposes a default timeout despite the documented default timeout being "never".  When this timeout occurs, axios confusingly reports an error "timeout of 0ms exceeded".  This change the message to avoid the confusing "0ms" part.

Co-authored-by: Jay <jasonsaayman@gmail.com>
2021-09-16 21:16:43 +02:00
Matt R. Wilson f3ca6371ca Caseless header comparing in HTTP adapter. (#2880)
* 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>
2021-09-07 20:30:30 +02:00
Fabiel Leon b5a1a67b3c Adding nodejs http.request option: insecureHTTPParser (#2930)
Co-authored-by: Jay <jasonsaayman@gmail.com>
2021-09-05 13:43:49 +02:00
Philipe Gouveia Paixão 199c8aab64 Adding parseInt to config.timeout (#3781)
* Adding parseInt to config.timeout

* Fixing test message
2021-05-06 15:54:22 +02:00
Mark 0ece97c7a9 Fixing quadratic runtime when setting a maxContentLength (#3738)
Previously checking whether a response has exceeded `maxContentLength` was
quadratic with respect to the number of chunks in the response stream and
also caused unnecessary additional memory usage.

Co-authored-by: Jay <jasonsaayman@gmail.com>
2021-05-04 19:48:20 +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
Mike Bishop b0959f0301 Adding ability to omit User-Agent header (#3703)
* 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>
2021-03-29 16:47:29 +02:00
Jonathan Foster e426910be7 Protocol not parsed when setting proxy config from env vars (#3070)
* 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
2020-12-03 09:36:50 +02:00
Daniel Lopretto c7329fefc8 Hotfix: Prevent SSRF (#3410)
* Reproducing the Vulnerability

* Prevent SSRF

* Cleanup

* Refactor to skip duplicate code

* Tests for correct passed data.

* Code review changes.
2020-11-24 08:44:00 +02:00
George Cheng 9a78465a92 Revert "Fixing overwrite Blob/File type as Content-Type in browser. (#1773)" (#3289)
This reverts commit f3cc053fb9.
2020-10-13 10:19:37 +02:00
Allan Cruz 04d45f2091 Fixing requestHeaders.Authorization (#3287) 2020-09-20 10:19:48 +08:00
Cr 16aa2ce7fa Fixing response with utf-8 BOM can not parse to json (#2419)
* fix: remove byte order marker (UTF-8 BOM) when transform response

* fix: remove BOM only utf-8

* test: utf-8 BOM

* fix: incorrect param name

Co-authored-by: Jay <jasonsaayman@gmail.com>
2020-07-01 19:14:52 +02:00
George Cheng f3cc053fb9 Fixing overwrite Blob/File type as Content-Type in browser. (#1773)
Co-authored-by: Jay <jasonsaayman@gmail.com>
2020-05-28 21:28:40 +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
huangzuizui a98755c00a fix 'Network Error' in react native android (#1487)
There is a bug in react native Android platform when using get method.  It will trigger a 'Network Error' when passing the requestData which is an empty string to request.send function. So if the  requestData is an empty string we can set it to null as well to fix the bug.

Co-authored-by: Jay <jasonsaayman@gmail.com>
2020-05-23 19:06:10 +02:00
Ryan Bown 1cdf9e4039 Fixing Cookie Helper with Asyc Components (#1105) (#1107)
Co-authored-by: Jay <jasonsaayman@gmail.com>
2020-05-22 16:44:17 +02:00
Spencer von der Ohe 42eb9dfabc Adding option to disable automatic decompression (#2661)
* Adding ability to disable auto decompression

* Updating decompress documentation in README

* Fixing test\unit\adapters\http.js lint errors

* Adding test for disabling auto decompression

* Removing changes that fixed lint errors in tests

* Removing formating change to unit test

Co-authored-by: Xianming Zhong <chinesedfan@qq.com>
2020-03-06 22:01:58 +08:00
Gustavo López 6642ca9aa1 Add independent maxBodyLength option (#2781)
* Add independent option to set the maximum size of the request body

* Remove maxBodyLength check

* Update README

* Assert for error code and message
2020-03-06 21:55:19 +08:00
Nikita Galkin 12e00b8018 Fixing issue for HEAD method and gziped repsonse (#2666) 2020-02-15 18:10:58 +08:00
Xianming Zhong 56b72bbd2c Compatible with follow-redirect aborts the request (#2689)
* Compatible with follow-redirect aborts the request

* Use the error code
2020-02-15 13:41:08 +08:00
Michael Shin 03e6f4bf4c Fixing invalid agent issue (#1904) 2019-12-25 12:55:36 -08:00
ZhaoXC dc4bc49673 fix: fix ignore set withCredentials false (#2582) 2019-12-08 23:52:45 -08:00
IVLIU 6284abfa06 custom timeout prompt copy (#2275)
* style: ui

* feat: custom timeout txtx

* feat: custom timeout txtx
2019-10-15 22:29:16 -03:00
Felipe Martins 85c9d4ffb0 fix: Fixing subdomain handling on no_proxy (#2442) 2019-09-28 20:51:20 -03:00
Jeremie Thomassey 00cd48027b Make redirection from HTTP to HTTPS work (#2426)
When calling an HTTP resource redirecting to a HTTPS one with a keepAlive agent. We get the following error:
```
TypeError [ERR_INVALID_PROTOCOL]: Protocol "https:" not supported. Expected "http:"
    at new ClientRequest (_http_client.js:119:11)
    at Object.request (https.js:281:10)
    at RedirectableRequest._performRequest (/Users/jthomassey/projects/ecom-shop-web/node_modules/follow-redirects/index.js:169:24)
    at RedirectableRequest._processResponse (/Users/jthomassey/projects/ecom-shop-web/node_modules/follow-redirects/index.js:260:10)
    at ClientRequest.RedirectableRequest._onNativeResponse (/Users/jthomassey/projects/ecom-shop-web/node_modules/follow-redirects/index.js:50:10)
    at Object.onceWrapper (events.js:277:13)
    at ClientRequest.emit (events.js:189:13)
    at HTTPParser.parserOnIncomingClient [as onIncoming] (_http_client.js:556:21)
    at HTTPParser.parserOnHeadersComplete (_http_common.js:109:17)
    at Socket.socketOnData (_http_client.js:442:20)
```

This can be tested here : 
```
const http = require('http');
const https = require('https');
const axios = require('axios');

axios.get('http://www.photobox.fr', { httpAgent: http.Agent({ keepAlive:true }), httpsAgent: https.Agent({ keepAlive:true }) })
  .then(response => {
    console.log(response);
    console.log(response.headers);
  })
  .catch(error => {
    console.log(error);
  });
```

Axios delegate the redirection to the follow-redirect package which accept an option `agents` for both http and https agent see : https://github.com/follow-redirects/follow-redirects#per-request-options
2019-09-26 09:33:49 -03:00
Ya Hui Liang(Ryou) 93e69625a6 Fixing socket hang up error on node side for slow response. (#1752)
* Fixing socket hang up error on node side for slow response.

* eslint check
2019-09-16 05:58:58 -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
drawski fd0c959355 Unzip response body only for statuses != 204 (#1129) 2019-05-15 13:35:09 -06:00
Gadzhi Gadzhiev 0d4fca085b Destroy stream on exceeding maxContentLength (fixes #1098) (#1485) 2019-05-07 15:20:34 -04:00
Rikki Gibson 21ae22dbd3 Preserve HTTP method when following redirect (#1758)
Resolves #1158

This modifies http.js to uppercase the HTTP method, similar to xhr.js, before passing the request off to the transport. This causes follow-redirects to preserve the HTTP method when automatically making a request to the next URL.
2018-08-27 17:26:38 +02:00
Chance Dickson 38de25257c Adding support for no_proxy env variable (#1693)
* Adding support for no_proxy env variable

* Adds support for the no_proxy environment variable commonly available
  with programs supporting the http_proxy/https_proxy environment
  variables.
* Adds tests to test the no_proxy environment variable.

* Adding documentation for the proxy env variables

* Adds documentation to README.md for the supported, conventional
  http_proxy, https_proxy, and no_proxy environment variables.
2018-08-07 11:52:04 -06:00
Rikki Gibson a9831131c3 Remove HTTP 1223 handling
The 1223 error was fixed in IE 10. See https://blogs.msdn.microsoft.com/ieinternals/2012/03/01/internet-explorer-10-consumer-preview-minor-changes-list/
2018-08-06 09:56:51 +02:00
Rikki Gibson 5c754e6e07 Remove ie8/9 special CORS treatment and btoa polyfill 2018-08-06 09:56:51 +02:00
Khaled Garbaya 7d9a29ee4c Fixing http adapter to allow HTTPS connections via HTTP (#959) 2018-07-04 23:51:11 -07:00
Mark van den Broek 787c808c04 Fix: Removes usage of deprecated Buffer constructor. (#1555) (#1622) 2018-07-04 23:47:17 -07:00
Justin Beckwith 22c2baf205 chore: upgrade eslint and add fix command 2018-04-06 21:50:26 -07:00
Justin Beckwith c65065ac0f capture errors on request data streams 2018-03-15 22:12:42 -07:00