未验证 提交 b6920570 编写于 作者: E Emily Morehouse 提交者: GitHub

Merge branch 'master' into bugfix/allow-method-in-instance-config

<!-- Click "Preview" for a more readable version -->
#### Instructions
#### Instructions
Please read and follow this instructions before submitting an issue:
Please read and follow the instructions before submitting an issue:
- Read all our documentation, specially the [README](https://github.com/axios/axios/blob/master/README.md). It may contain information that helps you solve your 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 for help, please use [Stack Overflow](https://stackoverflow.com/questions/tagged/axios) or [our chat](https://gitter.im/mzabriskie/axios).
- 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.
- If you need a new feature there's a chance it's already implemented in a [library](https://github.com/axios/axios/blob/master/ECOSYSTEM.md) or you can implement it using [interceptors](https://github.com/axios/axios#interceptors).
*^^^ Delete the instructions before submitting the issue ^^^*
**⚠️👆 Delete the instructions before submitting the issue 👆⚠️**
#### Summary
#### Summary
Describe your issue here, including as much detail as necessary.
......@@ -20,7 +20,7 @@ If you're reporting a bug, include the relevant code and stack traces to debug i
If you're requesting a feature, include some context and examples of code using it.
#### Context
#### Context
- axios version: *e.g.: v0.16.0*
- Environment: *e.g.: node v6.9.4, chrome 54, windows 7*
<!-- Click "Preview" for a more readable version -->
#### Instructions
#### Instructions
Please read and follow this instructions before creating and submitting a pull request:
Please read and follow the instructions before creating and submitting a pull request:
- Create an issue explaining the feature. It could save you some effort in case we don't consider it should be included in axios.
- If you're fixing a bug, try to commit the failing test/s and the code fixing it in different commits.
- Ensure you're following our [contributing guide](https://github.com/axios/axios/blob/master/CONTRIBUTING.md).
*^^^ Delete the instructions before submitting the pull request ^^^*
**⚠️👆 Delete the instructions before submitting the pull request 👆⚠️**
Describe your pull request here.
# 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))
- Allowing overriding transport ([#1080](https://github.com/axios/axios/pull/1080))
- Updating TypeScript typings ([#1165](https://github.com/axios/axios/pull/1165), [#1125](https://github.com/axios/axios/pull/1125), [#1131](https://github.com/axios/axios/pull/1131))
### 0.17.0 (Oct 21, 2017)
- **BREAKING** Fixing issue with `baseURL` and interceptors ([#950](https://github.com/axios/axios/pull/950))
- **BREAKING** Improving handing of duplicate headers ([#874](https://github.com/axios/axios/pull/874))
- Adding support for disabling proxies ([#691](https://github.com/axios/axios/pull/691))
- Updating TypeScript typings with generic type parameters ([#1061](https://github.com/axios/axios/pull/1061))
### 0.16.2 (Jun 3, 2017)
- Fixing issue with including `buffer` in bundle ([#887](https://github.com/axios/axios/pull/887))
......
......@@ -15,3 +15,6 @@ This is a list of axios related libraries and resources. If you have a suggestio
* [mocha-axios](https://github.com/jdrydn/mocha-axios) - Streamlined integration testing with Mocha & Axios
* [axiosist](https://github.com/Gerhut/axiosist) - Axios based supertest: convert node.js request handler to axios adapter, used for node.js server unit test.
* [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
Copyright (c) 2014 Matt Zabriskie
Copyright (c) 2014-present Matt Zabriskie
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
......
# axios
[![npm version](https://img.shields.io/npm/v/axios.svg?style=flat-square)](https://www.npmjs.org/package/axios)
[![build status](https://img.shields.io/travis/mzabriskie/axios.svg?style=flat-square)](https://travis-ci.org/mzabriskie/axios)
[![build status](https://img.shields.io/travis/axios/axios.svg?style=flat-square)](https://travis-ci.org/axios/axios)
[![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
......@@ -312,6 +313,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 +417,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
......@@ -521,6 +528,12 @@ axios.get('/user/12345', {
}
});
axios.post('/user/12345', {
name: 'new name'
}, {
cancelToken: source.token
})
// cancel the request (the message parameter is optional)
source.cancel('Operation canceled by the user.');
```
......
{
"name": "axios",
"main": "./dist/axios.js",
"version": "0.16.2",
"version": "0.18.0",
"homepage": "https://github.com/axios/axios",
"authors": [
"Matt Zabriskie"
......
/* axios v0.16.2 | (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();
......@@ -53,13 +53,13 @@ return /******/ (function(modules) { // webpackBootstrap
/************************************************************************/
/******/ ([
/* 0 */
/***/ function(module, exports, __webpack_require__) {
/***/ (function(module, exports, __webpack_require__) {
module.exports = __webpack_require__(1);
/***/ },
/***/ }),
/* 1 */
/***/ function(module, exports, __webpack_require__) {
/***/ (function(module, exports, __webpack_require__) {
'use strict';
......@@ -115,9 +115,9 @@ return /******/ (function(modules) { // webpackBootstrap
module.exports.default = axios;
/***/ },
/***/ }),
/* 2 */
/***/ function(module, exports, __webpack_require__) {
/***/ (function(module, exports, __webpack_require__) {
'use strict';
......@@ -328,7 +328,7 @@ return /******/ (function(modules) { // webpackBootstrap
}
// Force an array if not already something iterable
if (typeof obj !== 'object' && !isArray(obj)) {
if (typeof obj !== 'object') {
/*eslint no-param-reassign:0*/
obj = [obj];
}
......@@ -424,9 +424,9 @@ return /******/ (function(modules) { // webpackBootstrap
};
/***/ },
/***/ }),
/* 3 */
/***/ function(module, exports) {
/***/ (function(module, exports) {
'use strict';
......@@ -441,14 +441,14 @@ return /******/ (function(modules) { // webpackBootstrap
};
/***/ },
/***/ }),
/* 4 */
/***/ function(module, exports) {
/***/ (function(module, exports) {
/*!
* Determine if an object is a Buffer
*
* @author Feross Aboukhadijeh <feross@feross.org> <http://feross.org>
* @author Feross Aboukhadijeh <https://feross.org>
* @license MIT
*/
......@@ -468,9 +468,9 @@ return /******/ (function(modules) { // webpackBootstrap
}
/***/ },
/***/ }),
/* 5 */
/***/ function(module, exports, __webpack_require__) {
/***/ (function(module, exports, __webpack_require__) {
'use strict';
......@@ -478,8 +478,6 @@ return /******/ (function(modules) { // webpackBootstrap
var utils = __webpack_require__(2);
var InterceptorManager = __webpack_require__(17);
var dispatchRequest = __webpack_require__(18);
var isAbsoluteURL = __webpack_require__(21);
var combineURLs = __webpack_require__(22);
/**
* Create a new instance of Axios
......@@ -508,14 +506,9 @@ 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();
// Support baseURL config
if (config.baseURL && !isAbsoluteURL(config.url)) {
config.url = combineURLs(config.baseURL, config.url);
}
// Hook up interceptors middleware
var chain = [dispatchRequest, undefined];
var promise = Promise.resolve(config);
......@@ -560,9 +553,9 @@ return /******/ (function(modules) { // webpackBootstrap
module.exports = Axios;
/***/ },
/***/ }),
/* 6 */
/***/ function(module, exports, __webpack_require__) {
/***/ (function(module, exports, __webpack_require__) {
'use strict';
......@@ -629,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',
......@@ -658,9 +655,9 @@ return /******/ (function(modules) { // webpackBootstrap
module.exports = defaults;
/***/ },
/***/ }),
/* 7 */
/***/ function(module, exports, __webpack_require__) {
/***/ (function(module, exports, __webpack_require__) {
'use strict';
......@@ -676,9 +673,9 @@ return /******/ (function(modules) { // webpackBootstrap
};
/***/ },
/***/ }),
/* 8 */
/***/ function(module, exports, __webpack_require__) {
/***/ (function(module, exports, __webpack_require__) {
'use strict';
......@@ -748,7 +745,7 @@ return /******/ (function(modules) { // webpackBootstrap
var responseData = !config.responseType || config.responseType === 'text' ? request.responseText : request.response;
var response = {
data: responseData,
// IE sends 1223 instead of 204 (https://github.com/mzabriskie/axios/issues/201)
// IE sends 1223 instead of 204 (https://github.com/axios/axios/issues/201)
status: request.status === 1223 ? 204 : request.status,
statusText: request.status === 1223 ? 'No Content' : request.statusText,
headers: responseHeaders,
......@@ -862,9 +859,9 @@ return /******/ (function(modules) { // webpackBootstrap
};
/***/ },
/***/ }),
/* 9 */
/***/ function(module, exports, __webpack_require__) {
/***/ (function(module, exports, __webpack_require__) {
'use strict';
......@@ -894,9 +891,9 @@ return /******/ (function(modules) { // webpackBootstrap
};
/***/ },
/***/ }),
/* 10 */
/***/ function(module, exports, __webpack_require__) {
/***/ (function(module, exports, __webpack_require__) {
'use strict';
......@@ -918,9 +915,9 @@ return /******/ (function(modules) { // webpackBootstrap
};
/***/ },
/***/ }),
/* 11 */
/***/ function(module, exports) {
/***/ (function(module, exports) {
'use strict';
......@@ -945,9 +942,9 @@ return /******/ (function(modules) { // webpackBootstrap
};
/***/ },
/***/ }),
/* 12 */
/***/ function(module, exports, __webpack_require__) {
/***/ (function(module, exports, __webpack_require__) {
'use strict';
......@@ -992,9 +989,7 @@ return /******/ (function(modules) { // webpackBootstrap
if (utils.isArray(val)) {
key = key + '[]';
}
if (!utils.isArray(val)) {
} else {
val = [val];
}
......@@ -1019,14 +1014,23 @@ return /******/ (function(modules) { // webpackBootstrap
};
/***/ },
/***/ }),
/* 13 */
/***/ function(module, exports, __webpack_require__) {
/***/ (function(module, exports, __webpack_require__) {
'use strict';
var utils = __webpack_require__(2);
// Headers whose duplicates are ignored by node
// c.f. https://nodejs.org/api/http.html#http_message_headers
var ignoreDuplicateOf = [
'age', 'authorization', 'content-length', 'content-type', 'etag',
'expires', 'from', 'host', 'if-modified-since', 'if-unmodified-since',
'last-modified', 'location', 'max-forwards', 'proxy-authorization',
'referer', 'retry-after', 'user-agent'
];
/**
* Parse headers into an object
*
......@@ -1054,7 +1058,14 @@ return /******/ (function(modules) { // webpackBootstrap
val = utils.trim(line.substr(i + 1));
if (key) {
parsed[key] = parsed[key] ? parsed[key] + ', ' + val : val;
if (parsed[key] && ignoreDuplicateOf.indexOf(key) >= 0) {
return;
}
if (key === 'set-cookie') {
parsed[key] = (parsed[key] ? parsed[key] : []).concat([val]);
} else {
parsed[key] = parsed[key] ? parsed[key] + ', ' + val : val;
}
}
});
......@@ -1062,9 +1073,9 @@ return /******/ (function(modules) { // webpackBootstrap
};
/***/ },
/***/ }),
/* 14 */
/***/ function(module, exports, __webpack_require__) {
/***/ (function(module, exports, __webpack_require__) {
'use strict';
......@@ -1136,9 +1147,9 @@ return /******/ (function(modules) { // webpackBootstrap
);
/***/ },
/***/ }),
/* 15 */
/***/ function(module, exports) {
/***/ (function(module, exports) {
'use strict';
......@@ -1178,9 +1189,9 @@ return /******/ (function(modules) { // webpackBootstrap
module.exports = btoa;
/***/ },
/***/ }),
/* 16 */
/***/ function(module, exports, __webpack_require__) {
/***/ (function(module, exports, __webpack_require__) {
'use strict';
......@@ -1237,9 +1248,9 @@ return /******/ (function(modules) { // webpackBootstrap
);
/***/ },
/***/ }),
/* 17 */
/***/ function(module, exports, __webpack_require__) {
/***/ (function(module, exports, __webpack_require__) {
'use strict';
......@@ -1295,9 +1306,9 @@ return /******/ (function(modules) { // webpackBootstrap
module.exports = InterceptorManager;
/***/ },
/***/ }),
/* 18 */
/***/ function(module, exports, __webpack_require__) {
/***/ (function(module, exports, __webpack_require__) {
'use strict';
......@@ -1305,6 +1316,8 @@ return /******/ (function(modules) { // webpackBootstrap
var transformData = __webpack_require__(19);
var isCancel = __webpack_require__(20);
var defaults = __webpack_require__(6);
var isAbsoluteURL = __webpack_require__(21);
var combineURLs = __webpack_require__(22);
/**
* Throws a `Cancel` if cancellation has been requested.
......@@ -1324,6 +1337,11 @@ return /******/ (function(modules) { // webpackBootstrap
module.exports = function dispatchRequest(config) {
throwIfCancellationRequested(config);
// Support baseURL config
if (config.baseURL && !isAbsoluteURL(config.url)) {
config.url = combineURLs(config.baseURL, config.url);
}
// Ensure headers exist
config.headers = config.headers || {};
......@@ -1380,9 +1398,9 @@ return /******/ (function(modules) { // webpackBootstrap
};
/***/ },
/***/ }),
/* 19 */
/***/ function(module, exports, __webpack_require__) {
/***/ (function(module, exports, __webpack_require__) {
'use strict';
......@@ -1406,9 +1424,9 @@ return /******/ (function(modules) { // webpackBootstrap
};
/***/ },
/***/ }),
/* 20 */
/***/ function(module, exports) {
/***/ (function(module, exports) {
'use strict';
......@@ -1417,9 +1435,9 @@ return /******/ (function(modules) { // webpackBootstrap
};
/***/ },
/***/ }),
/* 21 */
/***/ function(module, exports) {
/***/ (function(module, exports) {
'use strict';
......@@ -1437,9 +1455,9 @@ return /******/ (function(modules) { // webpackBootstrap
};
/***/ },
/***/ }),
/* 22 */
/***/ function(module, exports) {
/***/ (function(module, exports) {
'use strict';
......@@ -1457,9 +1475,9 @@ return /******/ (function(modules) { // webpackBootstrap
};
/***/ },
/***/ }),
/* 23 */
/***/ function(module, exports) {
/***/ (function(module, exports) {
'use strict';
......@@ -1482,9 +1500,9 @@ return /******/ (function(modules) { // webpackBootstrap
module.exports = Cancel;
/***/ },
/***/ }),
/* 24 */
/***/ function(module, exports, __webpack_require__) {
/***/ (function(module, exports, __webpack_require__) {
'use strict';
......@@ -1545,9 +1563,9 @@ return /******/ (function(modules) { // webpackBootstrap
module.exports = CancelToken;
/***/ },
/***/ }),
/* 25 */
/***/ function(module, exports) {
/***/ (function(module, exports) {
'use strict';
......@@ -1578,7 +1596,7 @@ return /******/ (function(modules) { // webpackBootstrap
};
/***/ }
/***/ })
/******/ ])
});
;
......
此差异已折叠。
此差异已折叠。
因为 它太大了无法显示 source diff 。你可以改为 查看blob
export interface AxiosTransformer {
(data: any): any;
(data: any, headers?: any): any;
}
export interface AxiosAdapter {
(config: AxiosRequestConfig): AxiosPromise;
(config: AxiosRequestConfig): AxiosPromise<any>;
}
export interface AxiosBasicCredentials {
......@@ -14,6 +14,10 @@ export interface AxiosBasicCredentials {
export interface AxiosProxyConfig {
host: string;
port: number;
auth?: {
username: string;
password:string;
}
}
export interface AxiosRequestConfig {
......@@ -40,16 +44,17 @@ export interface AxiosRequestConfig {
maxRedirects?: number;
httpAgent?: any;
httpsAgent?: any;
proxy?: AxiosProxyConfig;
proxy?: AxiosProxyConfig | false;
cancelToken?: CancelToken;
}
export interface AxiosResponse {
data: any;
export interface AxiosResponse<T = any> {
data: T;
status: number;
statusText: string;
headers: any;
config: AxiosRequestConfig;
request?: any;
}
export interface AxiosError extends Error {
......@@ -59,7 +64,7 @@ export interface AxiosError extends Error {
response?: AxiosResponse;
}
export interface AxiosPromise extends Promise<AxiosResponse> {
export interface AxiosPromise<T = any> extends Promise<AxiosResponse<T>> {
}
export interface CancelStatic {
......@@ -91,28 +96,28 @@ export interface CancelTokenSource {
}
export interface AxiosInterceptorManager<V> {
use(onFulfilled: (value: V) => V | Promise<V>, onRejected?: (error: any) => any): number;
use(onFulfilled?: (value: V) => V | Promise<V>, onRejected?: (error: any) => any): number;
eject(id: number): void;
}
export interface AxiosInstance {
(config: AxiosRequestConfig): AxiosPromise;
(url: string, config?: AxiosRequestConfig): AxiosPromise;
defaults: AxiosRequestConfig;
interceptors: {
request: AxiosInterceptorManager<AxiosRequestConfig>;
response: AxiosInterceptorManager<AxiosResponse>;
};
request(config: AxiosRequestConfig): AxiosPromise;
get(url: string, config?: AxiosRequestConfig): AxiosPromise;
request<T = any>(config: AxiosRequestConfig): AxiosPromise<T>;
get<T = any>(url: string, config?: AxiosRequestConfig): AxiosPromise<T>;
delete(url: string, config?: AxiosRequestConfig): AxiosPromise;
head(url: string, config?: AxiosRequestConfig): AxiosPromise;
post(url: string, data?: any, config?: AxiosRequestConfig): AxiosPromise;
put(url: string, data?: any, config?: AxiosRequestConfig): AxiosPromise;
patch(url: string, data?: any, config?: AxiosRequestConfig): AxiosPromise;
post<T = any>(url: string, data?: any, config?: AxiosRequestConfig): AxiosPromise<T>;
put<T = any>(url: string, data?: any, config?: AxiosRequestConfig): AxiosPromise<T>;
patch<T = any>(url: string, data?: any, config?: AxiosRequestConfig): AxiosPromise<T>;
}
export interface AxiosStatic extends AxiosInstance {
(config: AxiosRequestConfig): AxiosPromise;
(url: string, config?: AxiosRequestConfig): AxiosPromise;
create(config?: AxiosRequestConfig): AxiosInstance;
Cancel: CancelStatic;
CancelToken: CancelTokenStatic;
......
......@@ -221,7 +221,7 @@ module.exports = function(config) {
sauceLabs: {
recordScreenshots: false,
connectOptions: {
port: 5757,
// port: 5757,
logfile: 'sauce_connect.log'
},
public: 'public'
......
......@@ -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';
......@@ -117,7 +122,9 @@ module.exports = function httpAdapter(config) {
}
var transport;
if (config.maxRedirects === 0) {
if (config.transport) {
transport = config.transport;
} else if (config.maxRedirects === 0) {
transport = isHttps ? https : http;
} else {
if (config.maxRedirects) {
......@@ -126,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;
......
......@@ -24,8 +24,7 @@ module.exports = function xhrAdapter(config) {
// For IE 8/9 CORS support
// Only supports POST and GET calls and doesn't returns the response headers.
// DON'T do this for testing b/c XMLHttpRequest is mocked, not XDomainRequest.
if (!window.XMLHttpRequest &&
process.env.NODE_ENV !== 'test' &&
if (process.env.NODE_ENV !== 'test' &&
typeof window !== 'undefined' &&
window.XDomainRequest && !('withCredentials' in request) &&
!isURLSameOrigin(config.url)) {
......
......@@ -64,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',
......
......@@ -41,9 +41,7 @@ module.exports = function buildURL(url, params, paramsSerializer) {
if (utils.isArray(val)) {
key = key + '[]';
}
if (!utils.isArray(val)) {
} else {
val = [val];
}
......
......@@ -207,7 +207,7 @@ function forEach(obj, fn) {
}
// Force an array if not already something iterable
if (typeof obj !== 'object' && !isArray(obj)) {
if (typeof obj !== 'object') {
/*eslint no-param-reassign:0*/
obj = [obj];
}
......
{
"name": "axios",
"version": "0.16.2",
"version": "0.18.0",
"description": "Promise based HTTP client for the browser and node.js",
"main": "index.js",
"scripts": {
......@@ -53,7 +53,6 @@
"karma-jasmine": "^1.0.2",
"karma-jasmine-ajax": "^0.1.13",
"karma-opera-launcher": "^1.0.0",
"karma-phantomjs-launcher": "^1.0.0",
"karma-safari-launcher": "^1.0.0",
"karma-sauce-launcher": "^1.1.0",
"karma-sinon": "^1.0.5",
......@@ -61,7 +60,6 @@
"karma-webpack": "^1.7.0",
"load-grunt-tasks": "^3.5.2",
"minimist": "^1.2.0",
"phantomjs-prebuilt": "^2.1.7",
"sinon": "^1.17.4",
"webpack": "^1.13.1",
"webpack-dev-server": "^1.14.1",
......@@ -73,7 +71,7 @@
},
"typings": "./index.d.ts",
"dependencies": {
"follow-redirects": "^1.2.3",
"follow-redirects": "^1.3.0",
"is-buffer": "^1.1.5"
},
"bundlesize": [
......
......@@ -97,11 +97,54 @@ axios.patch('/user', { foo: 'bar' })
.then(handleResponse)
.catch(handleError);
// Typed methods
interface User {
id: number;
name: string;
}
const handleUserResponse = (response: AxiosResponse<User>) => {
console.log(response.data.id);
console.log(response.data.name);
console.log(response.status);
console.log(response.statusText);
console.log(response.headers);
console.log(response.config);
};
axios.get<User>('/user?id=12345')
.then(handleUserResponse)
.catch(handleError);
axios.get<User>('/user', { params: { id: 12345 } })
.then(handleUserResponse)
.catch(handleError);
axios.post<User>('/user', { foo: 'bar' })
.then(handleUserResponse)
.catch(handleError);
axios.post<User>('/user', { foo: 'bar' }, { headers: { 'X-FOO': 'bar' } })
.then(handleUserResponse)
.catch(handleError);
axios.put<User>('/user', { foo: 'bar' })
.then(handleUserResponse)
.catch(handleError);
axios.patch<User>('/user', { foo: 'bar' })
.then(handleUserResponse)
.catch(handleError);
// Instances
const instance1: AxiosInstance = axios.create();
const instance2: AxiosInstance = axios.create(config);
instance1(config)
.then(handleResponse)
.catch(handleError);
instance1.request(config)
.then(handleResponse)
.catch(handleError);
......
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.
先完成此消息的编辑!
想要评论请 注册