From 81eaa3db4cf51bd911f98de5aa1ad130b3c55c8e Mon Sep 17 00:00:00 2001 From: Anatoly Ryabov Date: Tue, 4 Sep 2018 10:53:57 +0300 Subject: [PATCH 01/17] 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 `#` --- lib/helpers/buildURL.js | 5 +++++ test/specs/helpers/buildURL.spec.js | 6 ++++++ 2 files changed, 11 insertions(+) diff --git a/lib/helpers/buildURL.js b/lib/helpers/buildURL.js index be83cd0029..8c40e4096a 100644 --- a/lib/helpers/buildURL.js +++ b/lib/helpers/buildURL.js @@ -59,6 +59,11 @@ module.exports = function buildURL(url, params, paramsSerializer) { } if (serializedParams) { + var hashmarkIndex = url.indexOf('#'); + if (hashmarkIndex !== -1) { + url = url.slice(0, hashmarkIndex); + } + url += (url.indexOf('?') === -1 ? '?' : '&') + serializedParams; } diff --git a/test/specs/helpers/buildURL.spec.js b/test/specs/helpers/buildURL.spec.js index 83d7ba1640..b819f9d2eb 100644 --- a/test/specs/helpers/buildURL.spec.js +++ b/test/specs/helpers/buildURL.spec.js @@ -54,6 +54,12 @@ describe('helpers::buildURL', function () { })).toEqual('/foo?query=bar&start=0&length=5'); }); + it('should correct discard url hash mark', function () { + expect(buildURL('/foo?foo=bar#hash', { + query: 'baz' + })).toEqual('/foo?foo=bar&query=baz'); + }); + it('should use serializer if provided', function () { serializer = sinon.stub(); params = {foo: 'bar'}; From a74ab87df22a04932bcb1cc91d05dd0b2fa4ae9e Mon Sep 17 00:00:00 2001 From: Ali Servet Donmez Date: Mon, 17 Sep 2018 16:19:34 +0200 Subject: [PATCH 02/17] Consistent coding style (#1787) --- README.md | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 6c0bc57cdf..476d34a8fd 100755 --- a/README.md +++ b/README.md @@ -157,7 +157,7 @@ axios({ url:'http://bit.ly/2mTM3nY', responseType:'stream' }) - .then(function(response) { + .then(function (response) { response.data.pipe(fs.createWriteStream('ada_lovelace.jpg')) }); ``` @@ -267,7 +267,7 @@ These are the available config options for making requests. Only the `url` is re // `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) { + paramsSerializer: function (params) { return Qs.stringify(params, {arrayFormat: 'brackets'}) }, @@ -413,7 +413,7 @@ When using `then`, you will receive the response as follows: ```js axios.get('/user/12345') - .then(function(response) { + .then(function (response) { console.log(response.data); console.log(response.status); console.log(response.statusText); @@ -553,7 +553,7 @@ const source = CancelToken.source(); axios.get('/user/12345', { cancelToken: source.token -}).catch(function(thrown) { +}).catch(function (thrown) { if (axios.isCancel(thrown)) { console.log('Request canceled', thrown.message); } else { From 81f0d28eb5f8f3ec606fe0e282d4fbaea109c868 Mon Sep 17 00:00:00 2001 From: Manoel Date: Mon, 17 Sep 2018 11:24:46 -0300 Subject: [PATCH 03/17] Fixing .eslintrc without extension (#1789) --- .eslintrc => .eslintrc.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) rename .eslintrc => .eslintrc.js (99%) diff --git a/.eslintrc b/.eslintrc.js similarity index 99% rename from .eslintrc rename to .eslintrc.js index 22ae77fde2..7f9e73ed1c 100644 --- a/.eslintrc +++ b/.eslintrc.js @@ -1,4 +1,4 @@ -{ +module.exports = { "globals": { "console": true, "module": true, From 75c8b3f146aaa8a71f7dca0263686fb1799f8f31 Mon Sep 17 00:00:00 2001 From: Ken Powers Date: Mon, 17 Sep 2018 12:25:07 -0400 Subject: [PATCH 04/17] Allow uppercase methods in typings. (#1781) --- index.d.ts | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/index.d.ts b/index.d.ts index b60e43607c..0d4d6cc0ad 100644 --- a/index.d.ts +++ b/index.d.ts @@ -21,14 +21,14 @@ export interface AxiosProxyConfig { protocol?: string; } -export type Method = - | 'get' - | 'delete' - | 'head' - | 'options' - | 'post' - | 'put' - | 'patch' +export type Method = + | 'get' | 'GET' + | 'delete' | 'DELETE' + | 'head' | 'HEAD' + | 'options' | 'OPTIONS' + | 'post' | 'POST' + | 'put' | 'PUT' + | 'patch' | 'PATCH' export type ResponseType = | 'arraybuffer' From da3a85526297b78a00b71c960b0607688b8447be Mon Sep 17 00:00:00 2001 From: Cody Chan Date: Mon, 4 Feb 2019 11:54:49 +0800 Subject: [PATCH 05/17] Add react-hooks-axios to Libraries section of ECOSYSTEM.md (#1925) --- ECOSYSTEM.md | 1 + 1 file changed, 1 insertion(+) diff --git a/ECOSYSTEM.md b/ECOSYSTEM.md index a2b8cc7a3b..19760bd132 100644 --- a/ECOSYSTEM.md +++ b/ECOSYSTEM.md @@ -4,6 +4,7 @@ This is a list of axios related libraries and resources. If you have a suggestio ## Libraries +* [react-hooks-axios](https://github.com/use-hooks/react-hooks-axios) - Custom React Hooks for Axios.js * [moxios](https://github.com/axios/moxios) - Mock axios requests for testing * [axios-response-logger](https://github.com/srph/axios-response-logger) - Axios interceptor which logs responses * [axios-mock-adapter](https://github.com/ctimmerm/axios-mock-adapter) — Axios adapter that allows to easily mock requests From 71032ab5bd6ccadad04aeed286d2816ca2e84b43 Mon Sep 17 00:00:00 2001 From: Dmitriy Eroshenko Date: Mon, 4 Feb 2019 07:16:37 +0300 Subject: [PATCH 06/17] Update README.md. - Add Querystring library note (#1896) * Update README.md. Querystring libraries note * Typo in README.md Co-Authored-By: airs0urce * Update README.md Co-Authored-By: airs0urce --- README.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/README.md b/README.md index 476d34a8fd..1aab5f34cd 100755 --- a/README.md +++ b/README.md @@ -639,6 +639,9 @@ axios.post('http://something.com/', querystring.stringify({ foo: 'bar' })); You can also use the [`qs`](https://github.com/ljharb/qs) library. +###### NOTE +The `qs` library is preferable if you need to stringify nested objects, as the `querystring` method has known issues with that use case (https://github.com/nodejs/node-v0.x-archive/issues/1665). + ## Semver Until axios reaches a `1.0` release, breaking changes will be released with a new minor version. For example `0.5.1`, and `0.5.4` will have the same API, but `0.6.0` will have breaking changes. From e122c80c9ddb17e4dad2b6225da2ed9e95e986c7 Mon Sep 17 00:00:00 2001 From: Emily Morehouse Date: Sun, 3 Feb 2019 22:41:08 -0700 Subject: [PATCH 07/17] Add issue templates --- .github/ISSUE_TEMPLATE/---bug-report.md | 43 +++++++++++++++++++ .github/ISSUE_TEMPLATE/---documentation.md | 23 ++++++++++ .../---support-or-usage-question.md | 43 +++++++++++++++++++ .github/ISSUE_TEMPLATE/--feature-request.md | 20 +++++++++ 4 files changed, 129 insertions(+) create mode 100644 .github/ISSUE_TEMPLATE/---bug-report.md create mode 100644 .github/ISSUE_TEMPLATE/---documentation.md create mode 100644 .github/ISSUE_TEMPLATE/---support-or-usage-question.md create mode 100644 .github/ISSUE_TEMPLATE/--feature-request.md diff --git a/.github/ISSUE_TEMPLATE/---bug-report.md b/.github/ISSUE_TEMPLATE/---bug-report.md new file mode 100644 index 0000000000..a9f1fc9bb4 --- /dev/null +++ b/.github/ISSUE_TEMPLATE/---bug-report.md @@ -0,0 +1,43 @@ +--- +name: "\U0001F41E Bug Report" +about: Report a reproducible bug +title: '' +labels: bug +assignees: '' + +--- + + + +**Describe the bug** +A clear and concise description of what the bug is. **If your problem is not a bug, please file under Support or Usage Question** + +**To Reproduce** +Code snippet to reproduce, ideally that will work by pasting into something like https://npm.runkit.com/axios, a hosted solution, or a repository that illustrates the issue. **If your problem is not reproducible, please file under Support or Usage Question** + +```js +// Example code here +``` + +**Expected behavior** +A clear and concise description of what you expected to happen. + +**Environment:** + - Axios Version [e.g. 0.18.0] + - OS: [e.g. iOS 12.1.0, OSX 10.13.4] + - Browser [e.g. Chrome, Safari] + - Browser Version [e.g. 22] + - Additional Library Versions [e.g. React 16.7, React Native 0.58.0] + +**Additional context/Screenshots** +Add any other context about the problem here. If applicable, add screenshots to help explain. diff --git a/.github/ISSUE_TEMPLATE/---documentation.md b/.github/ISSUE_TEMPLATE/---documentation.md new file mode 100644 index 0000000000..0ce50ef5e8 --- /dev/null +++ b/.github/ISSUE_TEMPLATE/---documentation.md @@ -0,0 +1,23 @@ +--- +name: "\U0001F4DA Documentation" +about: Report an error or area that needs clarification +title: '' +labels: documentation +assignees: '' + +--- + + + +**Section/Content To Improve** +Quote or link to section + +**Suggested Improvement** +Identify what is confusing or incorrect and what could make it better + +**Relevant File(s)**: [e.g. README.md] diff --git a/.github/ISSUE_TEMPLATE/---support-or-usage-question.md b/.github/ISSUE_TEMPLATE/---support-or-usage-question.md new file mode 100644 index 0000000000..bba2dad340 --- /dev/null +++ b/.github/ISSUE_TEMPLATE/---support-or-usage-question.md @@ -0,0 +1,43 @@ +--- +name: "\U0001F914 Support or Usage Question" +about: Get help using Axios +title: '' +labels: question +assignees: '' + +--- + + + +**Describe the issue** +A clear and concise description of what the issue is. + +**Example Code** +Code snippet to illustrate your question + +```js +// Example code here +``` + +**Expected behavior, if applicable** +A clear and concise description of what you expected to happen. + +**Environment:** + - Axios Version [e.g. 0.18.0] + - OS: [e.g. iOS 12.1.0, OSX 10.13.4] + - Browser [e.g. Chrome, Safari] + - Browser Version [e.g. 22] + - Additional Library Versions [e.g. React 16.7, React Native 0.58.0] + +**Additional context/Screenshots** +Add any other context about the problem here. If applicable, add screenshots to help explain. diff --git a/.github/ISSUE_TEMPLATE/--feature-request.md b/.github/ISSUE_TEMPLATE/--feature-request.md new file mode 100644 index 0000000000..ad49bc0712 --- /dev/null +++ b/.github/ISSUE_TEMPLATE/--feature-request.md @@ -0,0 +1,20 @@ +--- +name: "✨ Feature Request" +about: Suggest an idea or feature +title: '' +labels: feature +assignees: '' + +--- + +**Is your feature request related to a problem? Please describe.** +A clear and concise description of what the problem is. Ex. I'm always frustrated when [...] + +**Describe the solution you'd like** +A clear and concise description of what you want to happen. + +**Describe alternatives you've considered** +A clear and concise description of any alternative solutions or features you've considered. + +**Additional context** +Add any other context or screenshots about the feature request here. From 2eeb59af4de41e07c7dd1eec09af0230960c029c Mon Sep 17 00:00:00 2001 From: grumblerchester Date: Fri, 8 Feb 2019 20:27:36 -0800 Subject: [PATCH 08/17] Fixing Mocha tests by locking follow-redirects version to 1.5.10 (#1993) --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 2229ce19f8..1289bb0a10 100644 --- a/package.json +++ b/package.json @@ -73,7 +73,7 @@ }, "typings": "./index.d.ts", "dependencies": { - "follow-redirects": "^1.4.1", + "follow-redirects": "1.5.10", "is-buffer": "^2.0.2" }, "bundlesize": [ From 283d7b306ce231f092d28e01713905e5c1600d14 Mon Sep 17 00:00:00 2001 From: Weffe Date: Mon, 4 Mar 2019 11:16:10 -0800 Subject: [PATCH 09/17] docs(ECOSYSTEM): add axios-api-versioning (#2020) --- ECOSYSTEM.md | 1 + 1 file changed, 1 insertion(+) diff --git a/ECOSYSTEM.md b/ECOSYSTEM.md index 19760bd132..6d705a2e8a 100644 --- a/ECOSYSTEM.md +++ b/ECOSYSTEM.md @@ -21,3 +21,4 @@ This is a list of axios related libraries and resources. If you have a suggestio * [axios-fetch](https://github.com/lifeomic/axios-fetch) - A WebAPI Fetch implementation backed by an Axios client * [axios-curlirize](https://www.npmjs.com/package/axios-curlirize) - Logs axios requests as curl commands, also adds a property to the response object with the curl command as value. * [axios-actions](https://github.com/davestewart/axios-actions) - Bundle endpoints as callable, reusable services +* [axios-api-versioning](https://weffe.github.io/axios-api-versioning) - Add easy to manage api versioning to axios From 047501f7083665e0924f2680846fd8721e6de50d Mon Sep 17 00:00:00 2001 From: Suman Lama Date: Tue, 7 May 2019 12:14:57 -0700 Subject: [PATCH 10/17] Makes Axios error generic to use AxiosResponse (#1738) --- index.d.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/index.d.ts b/index.d.ts index 0d4d6cc0ad..f934886659 100644 --- a/index.d.ts +++ b/index.d.ts @@ -76,11 +76,11 @@ export interface AxiosResponse { request?: any; } -export interface AxiosError extends Error { +export interface AxiosError extends Error { config: AxiosRequestConfig; code?: string; request?: any; - response?: AxiosResponse; + response?: AxiosResponse; isAxiosError: boolean; } From 0d4fca085b9b44e110f4c5a3dd7384c31abaf756 Mon Sep 17 00:00:00 2001 From: Gadzhi Gadzhiev Date: Tue, 7 May 2019 22:20:34 +0300 Subject: [PATCH 11/17] Destroy stream on exceeding maxContentLength (fixes #1098) (#1485) --- lib/adapters/http.js | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/adapters/http.js b/lib/adapters/http.js index d39a573a2a..e302bc0e46 100755 --- a/lib/adapters/http.js +++ b/lib/adapters/http.js @@ -216,6 +216,7 @@ module.exports = function httpAdapter(config) { // make sure the content length is not over the maxContentLength if specified if (config.maxContentLength > -1 && Buffer.concat(responseBuffer).length > config.maxContentLength) { + stream.destroy(); reject(createError('maxContentLength size of ' + config.maxContentLength + ' exceeded', config, null, lastRequest)); } From b7a9744518f71edad2991b48035e8cade37955a6 Mon Sep 17 00:00:00 2001 From: Tyler Breisacher Date: Tue, 7 May 2019 12:26:33 -0700 Subject: [PATCH 12/17] Clarify what values responseType can have in Node (#2121) It seems that `responseType: 'blob'` doesn't actually work in Node (when I tried using it, response.data was a string, not a Blob, since Node doesn't have Blobs), so this clarifies that this option should only be used in the browser --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 1aab5f34cd..29f15744b1 100755 --- a/README.md +++ b/README.md @@ -304,7 +304,8 @@ These are the available config options for making requests. Only the `url` is re }, // `responseType` indicates the type of data that the server will respond with - // options are 'arraybuffer', 'blob', 'document', 'json', 'text', 'stream' + // options are: 'arraybuffer', 'document', 'json', 'text', 'stream' + // browser only: 'blob' responseType: 'json', // default // `responseEncoding` indicates encoding to use for decoding responses From 48c43d5240e1ac6e6c44495e7428262d32a438f9 Mon Sep 17 00:00:00 2001 From: Omar Cai Date: Wed, 8 May 2019 04:01:44 +0800 Subject: [PATCH 13/17] Update README.md. - Change `.then` to `.finally` in example code (#2090) --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 29f15744b1..1d34885077 100755 --- a/README.md +++ b/README.md @@ -66,7 +66,7 @@ axios.get('/user?ID=12345') // handle error console.log(error); }) - .then(function () { + .finally(function () { // always executed }); From ddcc2e4bc0282499afc1370e3686bacaff1faee3 Mon Sep 17 00:00:00 2001 From: Josh McCarty <43768310+joshomccarty@users.noreply.github.com> Date: Tue, 7 May 2019 16:16:14 -0400 Subject: [PATCH 14/17] Fixing spacing for README.md (#2066) --- README.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 1d34885077..bc7cd4308e 100755 --- a/README.md +++ b/README.md @@ -153,9 +153,9 @@ axios({ ```js // GET request for remote image axios({ - method:'get', - url:'http://bit.ly/2mTM3nY', - responseType:'stream' + method: 'get', + url: 'http://bit.ly/2mTM3nY', + responseType: 'stream' }) .then(function (response) { response.data.pipe(fs.createWriteStream('ada_lovelace.jpg')) From 92d231387fe2092f8736bc1746d4caa766b675f5 Mon Sep 17 00:00:00 2001 From: Victor Hermes Date: Tue, 7 May 2019 17:17:16 -0300 Subject: [PATCH 15/17] Update README.md - Add instructions for installing with yarn (#2036) --- README.md | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/README.md b/README.md index bc7cd4308e..45583c94cc 100755 --- a/README.md +++ b/README.md @@ -43,6 +43,12 @@ Using bower: $ bower install axios ``` +Using yarn: + +```bash +$ yarn add axios +``` + Using cdn: ```html From fd0c959355e85afa76d1728b7c7bd93a05e004a4 Mon Sep 17 00:00:00 2001 From: drawski Date: Wed, 15 May 2019 21:35:09 +0200 Subject: [PATCH 16/17] Unzip response body only for statuses != 204 (#1129) --- lib/adapters/http.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/adapters/http.js b/lib/adapters/http.js index e302bc0e46..06169ff2cb 100755 --- a/lib/adapters/http.js +++ b/lib/adapters/http.js @@ -188,7 +188,7 @@ module.exports = function httpAdapter(config) { case 'compress': case 'deflate': // add the unzipper to the body stream processing pipeline - stream = stream.pipe(zlib.createUnzip()); + stream = (res.statusCode === 204) ? stream : stream.pipe(zlib.createUnzip()); // remove the content-encoding in order to not confuse downstream operations delete res.headers['content-encoding']; From 299e827c577c2f1461e17678282f4d19a753e6f2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=9C=A0=EC=9A=A9=EC=9A=B0=20/=20CX?= Date: Thu, 16 May 2019 04:40:23 +0900 Subject: [PATCH 17/17] Add r2curl in ECOSYSTEM (#2141) --- ECOSYSTEM.md | 1 + 1 file changed, 1 insertion(+) diff --git a/ECOSYSTEM.md b/ECOSYSTEM.md index 6d705a2e8a..41461ec31f 100644 --- a/ECOSYSTEM.md +++ b/ECOSYSTEM.md @@ -22,3 +22,4 @@ This is a list of axios related libraries and resources. If you have a suggestio * [axios-curlirize](https://www.npmjs.com/package/axios-curlirize) - Logs axios requests as curl commands, also adds a property to the response object with the curl command as value. * [axios-actions](https://github.com/davestewart/axios-actions) - Bundle endpoints as callable, reusable services * [axios-api-versioning](https://weffe.github.io/axios-api-versioning) - Add easy to manage api versioning to axios +* [r2curl](https://github.com/uyu423/r2curl) - Extracts the cURL command string from the Axios object. (AxiosResponse, AxiosRequestConfig)