mirror of
https://github.com/tenrok/axios.git
synced 2026-06-20 20:00:40 +03:00
Merge branch 'master' into instance-options
This commit is contained in:
@@ -1,5 +1,16 @@
|
|||||||
# Changelog
|
# Changelog
|
||||||
|
|
||||||
|
### 0.18.0 (Feb 19, 2018)
|
||||||
|
|
||||||
|
- Adding support for UNIX Sockets when running with Node.js ([#1070](https://github.com/axios/axios/pull/1070))
|
||||||
|
- Fixing typings ([#1177](https://github.com/axios/axios/pull/1177)):
|
||||||
|
- AxiosRequestConfig.proxy: allows type false
|
||||||
|
- AxiosProxyConfig: added auth field
|
||||||
|
- Adding function signature in AxiosInstance interface so AxiosInstance can be invoked ([#1192](https://github.com/axios/axios/pull/1192), [#1254](https://github.com/axios/axios/pull/1254))
|
||||||
|
- Allowing maxContentLength to pass through to redirected calls as maxBodyLength in follow-redirects config ([#1287](https://github.com/axios/axios/pull/1287))
|
||||||
|
- Fixing configuration when using an instance - method can now be set ([#1342](https://github.com/axios/axios/pull/1342))
|
||||||
|
|
||||||
|
|
||||||
### 0.17.1 (Nov 11, 2017)
|
### 0.17.1 (Nov 11, 2017)
|
||||||
|
|
||||||
- Fixing issue with web workers ([#1160](https://github.com/axios/axios/pull/1160))
|
- Fixing issue with web workers ([#1160](https://github.com/axios/axios/pull/1160))
|
||||||
|
|||||||
@@ -17,3 +17,4 @@ This is a list of axios related libraries and resources. If you have a suggestio
|
|||||||
* [axios-cache-plugin](https://github.com/jin5354/axios-cache-plugin) - Help you cache GET request when using axios.
|
* [axios-cache-plugin](https://github.com/jin5354/axios-cache-plugin) - Help you cache GET request when using axios.
|
||||||
* [axios-extensions](https://github.com/kuitos/axios-extensions) - A collection of axios extensions, including throttle and cache GET request plugin.
|
* [axios-extensions](https://github.com/kuitos/axios-extensions) - A collection of axios extensions, including throttle and cache GET request plugin.
|
||||||
* [redux-saga-requests](https://github.com/klis87/redux-saga-requests) - Redux-Saga addon to simplify handling of AJAX requests.
|
* [redux-saga-requests](https://github.com/klis87/redux-saga-requests) - Redux-Saga addon to simplify handling of AJAX requests.
|
||||||
|
* [axios-fetch](https://github.com/lifeomic/axios-fetch) - A WebAPI Fetch implementation backed by an Axios client
|
||||||
|
|||||||
@@ -5,6 +5,7 @@
|
|||||||
[](https://coveralls.io/r/mzabriskie/axios)
|
[](https://coveralls.io/r/mzabriskie/axios)
|
||||||
[](http://npm-stat.com/charts.html?package=axios)
|
[](http://npm-stat.com/charts.html?package=axios)
|
||||||
[](https://gitter.im/mzabriskie/axios)
|
[](https://gitter.im/mzabriskie/axios)
|
||||||
|
[](https://www.codetriage.com/axios/axios)
|
||||||
|
|
||||||
Promise based HTTP client for the browser and node.js
|
Promise based HTTP client for the browser and node.js
|
||||||
|
|
||||||
@@ -73,8 +74,21 @@ axios.get('/user', {
|
|||||||
.catch(function (error) {
|
.catch(function (error) {
|
||||||
console.log(error);
|
console.log(error);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// Want to use async/await? Add the `async` keyword to your outer function/method.
|
||||||
|
async function getUser() {
|
||||||
|
try {
|
||||||
|
const response = await axios.get('/user?ID=12345');
|
||||||
|
console.log(response);
|
||||||
|
} catch (error) {
|
||||||
|
console.error(error);
|
||||||
|
}
|
||||||
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
|
> **NOTE:** `async/await` is part of ECMAScript 2017 and is not supported in Internet
|
||||||
|
> Explorer and older browsers, so use with caution.
|
||||||
|
|
||||||
Performing a `POST` request
|
Performing a `POST` request
|
||||||
|
|
||||||
```js
|
```js
|
||||||
@@ -312,6 +326,12 @@ These are the available config options for making requests. Only the `url` is re
|
|||||||
// If set to 0, no redirects will be followed.
|
// If set to 0, no redirects will be followed.
|
||||||
maxRedirects: 5, // default
|
maxRedirects: 5, // default
|
||||||
|
|
||||||
|
// `socketPath` defines a UNIX Socket to be used in node.js.
|
||||||
|
// e.g. '/var/run/docker.sock' to send requests to the docker daemon.
|
||||||
|
// Only either `socketPath` or `proxy` can be specified.
|
||||||
|
// If both are specified, `socketPath` is used.
|
||||||
|
socketPath: null, // default
|
||||||
|
|
||||||
// `httpAgent` and `httpsAgent` define a custom agent to be used when performing http
|
// `httpAgent` and `httpsAgent` define a custom agent to be used when performing http
|
||||||
// and https requests, respectively, in node.js. This allows options to be added like
|
// and https requests, respectively, in node.js. This allows options to be added like
|
||||||
// `keepAlive` that are not enabled by default.
|
// `keepAlive` that are not enabled by default.
|
||||||
@@ -410,7 +430,7 @@ instance.defaults.headers.common['Authorization'] = AUTH_TOKEN;
|
|||||||
|
|
||||||
### Config order of precedence
|
### Config order of precedence
|
||||||
|
|
||||||
Config will be merged with an order of precedence. The order is library defaults found in `lib/defaults.js`, then `defaults` property of the instance, and finally `config` argument for the request. The latter will take precedence over the former. Here's an example.
|
Config will be merged with an order of precedence. The order is library defaults found in [lib/defaults.js](https://github.com/axios/axios/blob/master/lib/defaults.js#L28), then `defaults` property of the instance, and finally `config` argument for the request. The latter will take precedence over the former. Here's an example.
|
||||||
|
|
||||||
```js
|
```js
|
||||||
// Create an instance using the config defaults provided by the library
|
// Create an instance using the config defaults provided by the library
|
||||||
|
|||||||
+1
-1
@@ -1,7 +1,7 @@
|
|||||||
{
|
{
|
||||||
"name": "axios",
|
"name": "axios",
|
||||||
"main": "./dist/axios.js",
|
"main": "./dist/axios.js",
|
||||||
"version": "0.17.1",
|
"version": "0.18.0",
|
||||||
"homepage": "https://github.com/axios/axios",
|
"homepage": "https://github.com/axios/axios",
|
||||||
"authors": [
|
"authors": [
|
||||||
"Matt Zabriskie"
|
"Matt Zabriskie"
|
||||||
|
|||||||
Vendored
+8
-6
@@ -1,4 +1,4 @@
|
|||||||
/* axios v0.17.1 | (c) 2017 by Matt Zabriskie */
|
/* axios v0.18.0 | (c) 2018 by Matt Zabriskie */
|
||||||
(function webpackUniversalModuleDefinition(root, factory) {
|
(function webpackUniversalModuleDefinition(root, factory) {
|
||||||
if(typeof exports === 'object' && typeof module === 'object')
|
if(typeof exports === 'object' && typeof module === 'object')
|
||||||
module.exports = factory();
|
module.exports = factory();
|
||||||
@@ -448,7 +448,7 @@ return /******/ (function(modules) { // webpackBootstrap
|
|||||||
/*!
|
/*!
|
||||||
* Determine if an object is a Buffer
|
* Determine if an object is a Buffer
|
||||||
*
|
*
|
||||||
* @author Feross Aboukhadijeh <feross@feross.org> <http://feross.org>
|
* @author Feross Aboukhadijeh <https://feross.org>
|
||||||
* @license MIT
|
* @license MIT
|
||||||
*/
|
*/
|
||||||
|
|
||||||
@@ -506,7 +506,7 @@ return /******/ (function(modules) { // webpackBootstrap
|
|||||||
}, arguments[1]);
|
}, arguments[1]);
|
||||||
}
|
}
|
||||||
|
|
||||||
config = utils.merge(defaults, this.defaults, { method: 'get' }, config);
|
config = utils.merge(defaults, {method: 'get'}, this.defaults, config);
|
||||||
config.method = config.method.toLowerCase();
|
config.method = config.method.toLowerCase();
|
||||||
|
|
||||||
// Hook up interceptors middleware
|
// Hook up interceptors middleware
|
||||||
@@ -622,6 +622,10 @@ return /******/ (function(modules) { // webpackBootstrap
|
|||||||
return data;
|
return data;
|
||||||
}],
|
}],
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A timeout in milliseconds to abort a request. If set to 0 (default) a
|
||||||
|
* timeout is not created.
|
||||||
|
*/
|
||||||
timeout: 0,
|
timeout: 0,
|
||||||
|
|
||||||
xsrfCookieName: 'XSRF-TOKEN',
|
xsrfCookieName: 'XSRF-TOKEN',
|
||||||
@@ -985,9 +989,7 @@ return /******/ (function(modules) { // webpackBootstrap
|
|||||||
|
|
||||||
if (utils.isArray(val)) {
|
if (utils.isArray(val)) {
|
||||||
key = key + '[]';
|
key = key + '[]';
|
||||||
}
|
} else {
|
||||||
|
|
||||||
if (!utils.isArray(val)) {
|
|
||||||
val = [val];
|
val = [val];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Vendored
+1
-1
File diff suppressed because one or more lines are too long
Vendored
+3
-3
File diff suppressed because one or more lines are too long
Vendored
+1
-1
File diff suppressed because one or more lines are too long
Regular → Executable
+11
-2
@@ -72,8 +72,6 @@ module.exports = function httpAdapter(config) {
|
|||||||
var agent = isHttps ? config.httpsAgent : config.httpAgent;
|
var agent = isHttps ? config.httpsAgent : config.httpAgent;
|
||||||
|
|
||||||
var options = {
|
var options = {
|
||||||
hostname: parsed.hostname,
|
|
||||||
port: parsed.port,
|
|
||||||
path: buildURL(parsed.path, config.params, config.paramsSerializer).replace(/^\?/, ''),
|
path: buildURL(parsed.path, config.params, config.paramsSerializer).replace(/^\?/, ''),
|
||||||
method: config.method,
|
method: config.method,
|
||||||
headers: headers,
|
headers: headers,
|
||||||
@@ -81,6 +79,13 @@ module.exports = function httpAdapter(config) {
|
|||||||
auth: auth
|
auth: auth
|
||||||
};
|
};
|
||||||
|
|
||||||
|
if (config.socketPath) {
|
||||||
|
options.socketPath = config.socketPath;
|
||||||
|
} else {
|
||||||
|
options.hostname = parsed.hostname;
|
||||||
|
options.port = parsed.port;
|
||||||
|
}
|
||||||
|
|
||||||
var proxy = config.proxy;
|
var proxy = config.proxy;
|
||||||
if (!proxy && proxy !== false) {
|
if (!proxy && proxy !== false) {
|
||||||
var proxyEnv = protocol.slice(0, -1) + '_proxy';
|
var proxyEnv = protocol.slice(0, -1) + '_proxy';
|
||||||
@@ -128,6 +133,10 @@ module.exports = function httpAdapter(config) {
|
|||||||
transport = isHttps ? httpsFollow : httpFollow;
|
transport = isHttps ? httpsFollow : httpFollow;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (config.maxContentLength && config.maxContentLength > -1) {
|
||||||
|
options.maxBodyLength = config.maxContentLength;
|
||||||
|
}
|
||||||
|
|
||||||
// Create the request
|
// Create the request
|
||||||
var req = transport.request(options, function handleResponse(res) {
|
var req = transport.request(options, function handleResponse(res) {
|
||||||
if (req.aborted) return;
|
if (req.aborted) return;
|
||||||
|
|||||||
@@ -26,6 +26,7 @@ function getDefaultAdapter() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
var defaults = {
|
var defaults = {
|
||||||
|
method: 'get',
|
||||||
adapter: getDefaultAdapter(),
|
adapter: getDefaultAdapter(),
|
||||||
|
|
||||||
transformRequest: [function transformRequest(data, headers) {
|
transformRequest: [function transformRequest(data, headers) {
|
||||||
@@ -63,6 +64,10 @@ var defaults = {
|
|||||||
return data;
|
return data;
|
||||||
}],
|
}],
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A timeout in milliseconds to abort a request. If set to 0 (default) a
|
||||||
|
* timeout is not created.
|
||||||
|
*/
|
||||||
timeout: 0,
|
timeout: 0,
|
||||||
|
|
||||||
xsrfCookieName: 'XSRF-TOKEN',
|
xsrfCookieName: 'XSRF-TOKEN',
|
||||||
|
|||||||
+2
-2
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "axios",
|
"name": "axios",
|
||||||
"version": "0.17.1",
|
"version": "0.18.0",
|
||||||
"description": "Promise based HTTP client for the browser and node.js",
|
"description": "Promise based HTTP client for the browser and node.js",
|
||||||
"main": "index.js",
|
"main": "index.js",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
@@ -71,7 +71,7 @@
|
|||||||
},
|
},
|
||||||
"typings": "./index.d.ts",
|
"typings": "./index.d.ts",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"follow-redirects": "^1.2.5",
|
"follow-redirects": "^1.3.0",
|
||||||
"is-buffer": "^1.1.5"
|
"is-buffer": "^1.1.5"
|
||||||
},
|
},
|
||||||
"bundlesize": [
|
"bundlesize": [
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
var axios = require('../../../index');
|
var axios = require('../../../index');
|
||||||
var http = require('http');
|
var http = require('http');
|
||||||
|
var net = require('net');
|
||||||
var url = require('url');
|
var url = require('url');
|
||||||
var zlib = require('zlib');
|
var zlib = require('zlib');
|
||||||
var fs = require('fs');
|
var fs = require('fs');
|
||||||
@@ -228,6 +229,24 @@ module.exports = {
|
|||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
|
||||||
|
testSocket: function (test) {
|
||||||
|
server = net.createServer(function (socket) {
|
||||||
|
socket.on('data', function() {
|
||||||
|
socket.end('HTTP/1.1 200 OK\r\n\r\n');
|
||||||
|
});
|
||||||
|
}).listen('./test.sock', function() {
|
||||||
|
axios({
|
||||||
|
socketPath: './test.sock',
|
||||||
|
url: '/'
|
||||||
|
})
|
||||||
|
.then(function(resp) {
|
||||||
|
test.equal(resp.status, 200);
|
||||||
|
test.equal(resp.statusText, 'OK');
|
||||||
|
test.done();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
},
|
||||||
|
|
||||||
testStream: function(test) {
|
testStream: function(test) {
|
||||||
server = http.createServer(function (req, res) {
|
server = http.createServer(function (req, res) {
|
||||||
req.pipe(res);
|
req.pipe(res);
|
||||||
|
|||||||
Reference in New Issue
Block a user