Skip to content

Commit

Permalink
Merge branch 'master' into content-type
Browse files Browse the repository at this point in the history
  • Loading branch information
Gerhut committed May 27, 2019
2 parents 6b99b6e + 299e827 commit 0070708
Show file tree
Hide file tree
Showing 12 changed files with 176 additions and 22 deletions.
2 changes: 1 addition & 1 deletion .eslintrc → .eslintrc.js
@@ -1,4 +1,4 @@
{
module.exports = {
"globals": {
"console": true,
"module": true,
Expand Down
43 changes: 43 additions & 0 deletions .github/ISSUE_TEMPLATE/---bug-report.md
@@ -0,0 +1,43 @@
---
name: "\U0001F41E Bug Report"
about: Report a reproducible bug
title: ''
labels: bug
assignees: ''

---

<!-- Click "Preview" for a more readable version --
Please read and follow the instructions before submitting an issue:
- Read all our documentation, especially the [README](https://github.com/axios/axios/blob/master/README.md). It may contain information that helps you solve your issue.
- Ensure your issue isn't already [reported](https://github.com/axios/axios/issues?utf8=%E2%9C%93&q=is%3Aissue).
- If you aren't sure that the issue is caused by Axios or you just need help, please use [Stack Overflow](https://stackoverflow.com/questions/tagged/axios) or [our chat](https://gitter.im/mzabriskie/axios).
- If you're reporting a bug, ensure it isn't already fixed in the latest Axios version.
⚠️👆 Feel free to these instructions before submitting the issue 👆⚠️
-->

**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.
23 changes: 23 additions & 0 deletions .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: ''

---

<!-- Click "Preview" for a more readable version --
If you found an area that needs clarification, feel free to open a PR or list the section/content that could be improved below
⚠️👆 Feel free to these instructions before submitting the issue 👆⚠️
-->

**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]
43 changes: 43 additions & 0 deletions .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: ''

---

<!-- Click "Preview" for a more readable version --
Please read and follow the instructions before submitting an issue:
- Read all our documentation, especially the [README](https://github.com/axios/axios/blob/master/README.md). It may contain information that helps you solve your issue.
- Ensure your issue isn't already [reported](https://github.com/axios/axios/issues?utf8=%E2%9C%93&q=is%3Aissue).
- If you aren't sure that the issue is caused by Axios or you just need help, please use [Stack Overflow](https://stackoverflow.com/questions/tagged/axios) or [our chat](https://gitter.im/mzabriskie/axios).
- If you're reporting a bug, ensure it isn't already fixed in the latest Axios version.
⚠️👆 Feel free to these instructions before submitting the issue 👆⚠️
-->

**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.
20 changes: 20 additions & 0 deletions .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.
3 changes: 3 additions & 0 deletions ECOSYSTEM.md
Expand Up @@ -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
Expand All @@ -20,3 +21,5 @@ 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
* [r2curl](https://github.com/uyu423/r2curl) - Extracts the cURL command string from the Axios object. (AxiosResponse, AxiosRequestConfig)
28 changes: 19 additions & 9 deletions README.md
Expand Up @@ -43,6 +43,12 @@ Using bower:
$ bower install axios
```

Using yarn:

```bash
$ yarn add axios
```

Using cdn:

```html
Expand All @@ -66,7 +72,7 @@ axios.get('/user?ID=12345')
// handle error
console.log(error);
})
.then(function () {
.finally(function () {
// always executed
});

Expand Down Expand Up @@ -153,11 +159,11 @@ 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) {
.then(function (response) {
response.data.pipe(fs.createWriteStream('ada_lovelace.jpg'))
});
```
Expand Down Expand Up @@ -267,7 +273,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'})
},

Expand Down Expand Up @@ -304,7 +310,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
Expand Down Expand Up @@ -413,7 +420,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);
Expand Down Expand Up @@ -553,7 +560,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 {
Expand Down Expand Up @@ -639,6 +646,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.
Expand Down
20 changes: 10 additions & 10 deletions index.d.ts
Expand Up @@ -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'
Expand Down Expand Up @@ -76,11 +76,11 @@ export interface AxiosResponse<T = any> {
request?: any;
}

export interface AxiosError extends Error {
export interface AxiosError<T = any> extends Error {
config: AxiosRequestConfig;
code?: string;
request?: any;
response?: AxiosResponse;
response?: AxiosResponse<T>;
isAxiosError: boolean;
}

Expand Down
3 changes: 2 additions & 1 deletion lib/adapters/http.js
Expand Up @@ -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'];
Expand Down Expand Up @@ -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));
}
Expand Down
5 changes: 5 additions & 0 deletions lib/helpers/buildURL.js
Expand Up @@ -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;
}

Expand Down
2 changes: 1 addition & 1 deletion package.json
Expand Up @@ -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": [
Expand Down
6 changes: 6 additions & 0 deletions test/specs/helpers/buildURL.spec.js
Expand Up @@ -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'};
Expand Down

0 comments on commit 0070708

Please sign in to comment.