提交 d1154eae 编写于 作者: M Martti Laine

Merge branch 'instance-options' of github.com:codeclown/axios into instance-options

# 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)
- 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-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.
* [axios-fetch](https://github.com/lifeomic/axios-fetch) - A WebAPI Fetch implementation backed by an Axios client
......@@ -5,6 +5,7 @@
[![code coverage](https://img.shields.io/coveralls/mzabriskie/axios.svg?style=flat-square)](https://coveralls.io/r/mzabriskie/axios)
[![npm downloads](https://img.shields.io/npm/dm/axios.svg?style=flat-square)](http://npm-stat.com/charts.html?package=axios)
[![gitter chat](https://img.shields.io/gitter/room/mzabriskie/axios.svg?style=flat-square)](https://gitter.im/mzabriskie/axios)
[![code helpers](https://www.codetriage.com/axios/axios/badges/users.svg)](https://www.codetriage.com/axios/axios)
Promise based HTTP client for the browser and node.js
......@@ -73,8 +74,21 @@ axios.get('/user', {
.catch(function (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
```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.
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
// and https requests, respectively, in node.js. This allows options to be added like
// `keepAlive` that are not enabled by default.
......@@ -410,7 +430,7 @@ instance.defaults.headers.common['Authorization'] = AUTH_TOKEN;
### 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
// Create an instance using the config defaults provided by the library
......
{
"name": "axios",
"main": "./dist/axios.js",
"version": "0.17.1",
"version": "0.18.0",
"homepage": "https://github.com/axios/axios",
"authors": [
"Matt Zabriskie"
......
/* axios v0.17.1 | (c) 2017 by Matt Zabriskie */
/* axios v0.18.0 | (c) 2018 by Matt Zabriskie */
(function webpackUniversalModuleDefinition(root, factory) {
if(typeof exports === 'object' && typeof module === 'object')
module.exports = factory();
......@@ -448,7 +448,7 @@ return /******/ (function(modules) { // webpackBootstrap
/*!
* Determine if an object is a Buffer
*
* @author Feross Aboukhadijeh <feross@feross.org> <http://feross.org>
* @author Feross Aboukhadijeh <https://feross.org>
* @license MIT
*/
......@@ -506,7 +506,7 @@ return /******/ (function(modules) { // webpackBootstrap
}, 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();
// Hook up interceptors middleware
......@@ -622,6 +622,10 @@ return /******/ (function(modules) { // webpackBootstrap
return data;
}],
/**
* A timeout in milliseconds to abort a request. If set to 0 (default) a
* timeout is not created.
*/
timeout: 0,
xsrfCookieName: 'XSRF-TOKEN',
......@@ -985,9 +989,7 @@ return /******/ (function(modules) { // webpackBootstrap
if (utils.isArray(val)) {
key = key + '[]';
}
if (!utils.isArray(val)) {
} else {
val = [val];
}
......
此差异已折叠。
此差异已折叠。
因为 它太大了无法显示 source diff 。你可以改为 查看blob
......@@ -72,8 +72,6 @@ module.exports = function httpAdapter(config) {
var agent = isHttps ? config.httpsAgent : config.httpAgent;
var options = {
hostname: parsed.hostname,
port: parsed.port,
path: buildURL(parsed.path, config.params, config.paramsSerializer).replace(/^\?/, ''),
method: config.method,
headers: headers,
......@@ -81,6 +79,13 @@ module.exports = function httpAdapter(config) {
auth: auth
};
if (config.socketPath) {
options.socketPath = config.socketPath;
} else {
options.hostname = parsed.hostname;
options.port = parsed.port;
}
var proxy = config.proxy;
if (!proxy && proxy !== false) {
var proxyEnv = protocol.slice(0, -1) + '_proxy';
......@@ -128,6 +133,10 @@ module.exports = function httpAdapter(config) {
transport = isHttps ? httpsFollow : httpFollow;
}
if (config.maxContentLength && config.maxContentLength > -1) {
options.maxBodyLength = config.maxContentLength;
}
// Create the request
var req = transport.request(options, function handleResponse(res) {
if (req.aborted) return;
......
......@@ -26,6 +26,7 @@ function getDefaultAdapter() {
}
var defaults = {
method: 'get',
adapter: getDefaultAdapter(),
transformRequest: [function transformRequest(data, headers) {
......@@ -63,6 +64,10 @@ var defaults = {
return data;
}],
/**
* A timeout in milliseconds to abort a request. If set to 0 (default) a
* timeout is not created.
*/
timeout: 0,
xsrfCookieName: 'XSRF-TOKEN',
......
{
"name": "axios",
"version": "0.17.1",
"version": "0.18.0",
"description": "Promise based HTTP client for the browser and node.js",
"main": "index.js",
"scripts": {
......@@ -71,7 +71,7 @@
},
"typings": "./index.d.ts",
"dependencies": {
"follow-redirects": "^1.2.5",
"follow-redirects": "^1.3.0",
"is-buffer": "^1.1.5"
},
"bundlesize": [
......
var axios = require('../../../index');
var http = require('http');
var net = require('net');
var url = require('url');
var zlib = require('zlib');
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) {
server = http.createServer(function (req, res) {
req.pipe(res);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册