axios 0.17.1 → 0.19.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.

Potentially problematic release.


This version of axios might be problematic. Click here for more details.

package/index.d.ts CHANGED
@@ -14,11 +14,33 @@ export interface AxiosBasicCredentials {
14
14
  export interface AxiosProxyConfig {
15
15
  host: string;
16
16
  port: number;
17
- }
17
+ auth?: {
18
+ username: string;
19
+ password:string;
20
+ };
21
+ protocol?: string;
22
+ }
23
+
24
+ export type Method =
25
+ | 'get' | 'GET'
26
+ | 'delete' | 'DELETE'
27
+ | 'head' | 'HEAD'
28
+ | 'options' | 'OPTIONS'
29
+ | 'post' | 'POST'
30
+ | 'put' | 'PUT'
31
+ | 'patch' | 'PATCH'
32
+
33
+ export type ResponseType =
34
+ | 'arraybuffer'
35
+ | 'blob'
36
+ | 'document'
37
+ | 'json'
38
+ | 'text'
39
+ | 'stream'
18
40
 
19
41
  export interface AxiosRequestConfig {
20
42
  url?: string;
21
- method?: string;
43
+ method?: Method;
22
44
  baseURL?: string;
23
45
  transformRequest?: AxiosTransformer | AxiosTransformer[];
24
46
  transformResponse?: AxiosTransformer | AxiosTransformer[];
@@ -30,7 +52,7 @@ export interface AxiosRequestConfig {
30
52
  withCredentials?: boolean;
31
53
  adapter?: AxiosAdapter;
32
54
  auth?: AxiosBasicCredentials;
33
- responseType?: string;
55
+ responseType?: ResponseType;
34
56
  xsrfCookieName?: string;
35
57
  xsrfHeaderName?: string;
36
58
  onUploadProgress?: (progressEvent: any) => void;
@@ -38,9 +60,10 @@ export interface AxiosRequestConfig {
38
60
  maxContentLength?: number;
39
61
  validateStatus?: (status: number) => boolean;
40
62
  maxRedirects?: number;
63
+ socketPath?: string | null;
41
64
  httpAgent?: any;
42
65
  httpsAgent?: any;
43
- proxy?: AxiosProxyConfig;
66
+ proxy?: AxiosProxyConfig | false;
44
67
  cancelToken?: CancelToken;
45
68
  }
46
69
 
@@ -53,11 +76,12 @@ export interface AxiosResponse<T = any> {
53
76
  request?: any;
54
77
  }
55
78
 
56
- export interface AxiosError extends Error {
79
+ export interface AxiosError<T = any> extends Error {
57
80
  config: AxiosRequestConfig;
58
81
  code?: string;
59
82
  request?: any;
60
- response?: AxiosResponse;
83
+ response?: AxiosResponse<T>;
84
+ isAxiosError: boolean;
61
85
  }
62
86
 
63
87
  export interface AxiosPromise<T = any> extends Promise<AxiosResponse<T>> {
@@ -97,23 +121,24 @@ export interface AxiosInterceptorManager<V> {
97
121
  }
98
122
 
99
123
  export interface AxiosInstance {
124
+ (config: AxiosRequestConfig): AxiosPromise;
125
+ (url: string, config?: AxiosRequestConfig): AxiosPromise;
100
126
  defaults: AxiosRequestConfig;
101
127
  interceptors: {
102
128
  request: AxiosInterceptorManager<AxiosRequestConfig>;
103
129
  response: AxiosInterceptorManager<AxiosResponse>;
104
130
  };
105
- request<T = any>(config: AxiosRequestConfig): AxiosPromise<T>;
106
- get<T = any>(url: string, config?: AxiosRequestConfig): AxiosPromise<T>;
107
- delete(url: string, config?: AxiosRequestConfig): AxiosPromise;
108
- head(url: string, config?: AxiosRequestConfig): AxiosPromise;
109
- post<T = any>(url: string, data?: any, config?: AxiosRequestConfig): AxiosPromise<T>;
110
- put<T = any>(url: string, data?: any, config?: AxiosRequestConfig): AxiosPromise<T>;
111
- patch<T = any>(url: string, data?: any, config?: AxiosRequestConfig): AxiosPromise<T>;
131
+ getUri(config?: AxiosRequestConfig): string;
132
+ request<T = any, R = AxiosResponse<T>> (config: AxiosRequestConfig): Promise<R>;
133
+ get<T = any, R = AxiosResponse<T>>(url: string, config?: AxiosRequestConfig): Promise<R>;
134
+ delete<T = any, R = AxiosResponse<T>>(url: string, config?: AxiosRequestConfig): Promise<R>;
135
+ head<T = any, R = AxiosResponse<T>>(url: string, config?: AxiosRequestConfig): Promise<R>;
136
+ post<T = any, R = AxiosResponse<T>>(url: string, data?: any, config?: AxiosRequestConfig): Promise<R>;
137
+ put<T = any, R = AxiosResponse<T>>(url: string, data?: any, config?: AxiosRequestConfig): Promise<R>;
138
+ patch<T = any, R = AxiosResponse<T>>(url: string, data?: any, config?: AxiosRequestConfig): Promise<R>;
112
139
  }
113
140
 
114
141
  export interface AxiosStatic extends AxiosInstance {
115
- (config: AxiosRequestConfig): AxiosPromise;
116
- (url: string, config?: AxiosRequestConfig): AxiosPromise;
117
142
  create(config?: AxiosRequestConfig): AxiosInstance;
118
143
  Cancel: CancelStatic;
119
144
  CancelToken: CancelTokenStatic;
@@ -13,12 +13,22 @@ var pkg = require('./../../package.json');
13
13
  var createError = require('../core/createError');
14
14
  var enhanceError = require('../core/enhanceError');
15
15
 
16
+ var isHttps = /https:?/;
17
+
16
18
  /*eslint consistent-return:0*/
17
19
  module.exports = function httpAdapter(config) {
18
- return new Promise(function dispatchHttpRequest(resolve, reject) {
20
+ return new Promise(function dispatchHttpRequest(resolvePromise, rejectPromise) {
21
+ var timer;
22
+ var resolve = function resolve(value) {
23
+ clearTimeout(timer);
24
+ resolvePromise(value);
25
+ };
26
+ var reject = function reject(value) {
27
+ clearTimeout(timer);
28
+ rejectPromise(value);
29
+ };
19
30
  var data = config.data;
20
31
  var headers = config.headers;
21
- var timer;
22
32
 
23
33
  // Set User-Agent (required by some servers)
24
34
  // Only set header if it hasn't been set in config
@@ -31,9 +41,9 @@ module.exports = function httpAdapter(config) {
31
41
  if (Buffer.isBuffer(data)) {
32
42
  // Nothing to do...
33
43
  } else if (utils.isArrayBuffer(data)) {
34
- data = new Buffer(new Uint8Array(data));
44
+ data = Buffer.from(new Uint8Array(data));
35
45
  } else if (utils.isString(data)) {
36
- data = new Buffer(data, 'utf-8');
46
+ data = Buffer.from(data, 'utf-8');
37
47
  } else {
38
48
  return reject(createError(
39
49
  'Data after transformation must be a string, an ArrayBuffer, a Buffer, or a Stream',
@@ -68,36 +78,69 @@ module.exports = function httpAdapter(config) {
68
78
  delete headers.Authorization;
69
79
  }
70
80
 
71
- var isHttps = protocol === 'https:';
72
- var agent = isHttps ? config.httpsAgent : config.httpAgent;
81
+ var isHttpsRequest = isHttps.test(protocol);
82
+ var agent = isHttpsRequest ? config.httpsAgent : config.httpAgent;
73
83
 
74
84
  var options = {
75
- hostname: parsed.hostname,
76
- port: parsed.port,
77
85
  path: buildURL(parsed.path, config.params, config.paramsSerializer).replace(/^\?/, ''),
78
- method: config.method,
86
+ method: config.method.toUpperCase(),
79
87
  headers: headers,
80
88
  agent: agent,
81
89
  auth: auth
82
90
  };
83
91
 
92
+ if (config.socketPath) {
93
+ options.socketPath = config.socketPath;
94
+ } else {
95
+ options.hostname = parsed.hostname;
96
+ options.port = parsed.port;
97
+ }
98
+
84
99
  var proxy = config.proxy;
85
100
  if (!proxy && proxy !== false) {
86
101
  var proxyEnv = protocol.slice(0, -1) + '_proxy';
87
102
  var proxyUrl = process.env[proxyEnv] || process.env[proxyEnv.toUpperCase()];
88
103
  if (proxyUrl) {
89
104
  var parsedProxyUrl = url.parse(proxyUrl);
90
- proxy = {
91
- host: parsedProxyUrl.hostname,
92
- port: parsedProxyUrl.port
93
- };
94
-
95
- if (parsedProxyUrl.auth) {
96
- var proxyUrlAuth = parsedProxyUrl.auth.split(':');
97
- proxy.auth = {
98
- username: proxyUrlAuth[0],
99
- password: proxyUrlAuth[1]
105
+ var noProxyEnv = process.env.no_proxy || process.env.NO_PROXY;
106
+ var shouldProxy = true;
107
+
108
+ if (noProxyEnv) {
109
+ var noProxy = noProxyEnv.split(',').map(function trim(s) {
110
+ return s.trim();
111
+ });
112
+
113
+ shouldProxy = !noProxy.some(function proxyMatch(proxyElement) {
114
+ if (!proxyElement) {
115
+ return false;
116
+ }
117
+ if (proxyElement === '*') {
118
+ return true;
119
+ }
120
+ if (proxyElement[0] === '.' &&
121
+ parsed.hostname.substr(parsed.hostname.length - proxyElement.length) === proxyElement &&
122
+ proxyElement.match(/\./g).length === parsed.hostname.match(/\./g).length) {
123
+ return true;
124
+ }
125
+
126
+ return parsed.hostname === proxyElement;
127
+ });
128
+ }
129
+
130
+
131
+ if (shouldProxy) {
132
+ proxy = {
133
+ host: parsedProxyUrl.hostname,
134
+ port: parsedProxyUrl.port
100
135
  };
136
+
137
+ if (parsedProxyUrl.auth) {
138
+ var proxyUrlAuth = parsedProxyUrl.auth.split(':');
139
+ proxy.auth = {
140
+ username: proxyUrlAuth[0],
141
+ password: proxyUrlAuth[1]
142
+ };
143
+ }
101
144
  }
102
145
  }
103
146
  }
@@ -111,31 +154,32 @@ module.exports = function httpAdapter(config) {
111
154
 
112
155
  // Basic proxy authorization
113
156
  if (proxy.auth) {
114
- var base64 = new Buffer(proxy.auth.username + ':' + proxy.auth.password, 'utf8').toString('base64');
157
+ var base64 = Buffer.from(proxy.auth.username + ':' + proxy.auth.password, 'utf8').toString('base64');
115
158
  options.headers['Proxy-Authorization'] = 'Basic ' + base64;
116
159
  }
117
160
  }
118
161
 
119
162
  var transport;
163
+ var isHttpsProxy = isHttpsRequest && (proxy ? isHttps.test(proxy.protocol) : true);
120
164
  if (config.transport) {
121
165
  transport = config.transport;
122
166
  } else if (config.maxRedirects === 0) {
123
- transport = isHttps ? https : http;
167
+ transport = isHttpsProxy ? https : http;
124
168
  } else {
125
169
  if (config.maxRedirects) {
126
170
  options.maxRedirects = config.maxRedirects;
127
171
  }
128
- transport = isHttps ? httpsFollow : httpFollow;
172
+ transport = isHttpsProxy ? httpsFollow : httpFollow;
173
+ }
174
+
175
+ if (config.maxContentLength && config.maxContentLength > -1) {
176
+ options.maxBodyLength = config.maxContentLength;
129
177
  }
130
178
 
131
179
  // Create the request
132
180
  var req = transport.request(options, function handleResponse(res) {
133
181
  if (req.aborted) return;
134
182
 
135
- // Response has been received so kill timer that handles request timeout
136
- clearTimeout(timer);
137
- timer = null;
138
-
139
183
  // uncompress the response body transparently if required
140
184
  var stream = res;
141
185
  switch (res.headers['content-encoding']) {
@@ -144,7 +188,7 @@ module.exports = function httpAdapter(config) {
144
188
  case 'compress':
145
189
  case 'deflate':
146
190
  // add the unzipper to the body stream processing pipeline
147
- stream = stream.pipe(zlib.createUnzip());
191
+ stream = (res.statusCode === 204) ? stream : stream.pipe(zlib.createUnzip());
148
192
 
149
193
  // remove the content-encoding in order to not confuse downstream operations
150
194
  delete res.headers['content-encoding'];
@@ -172,6 +216,7 @@ module.exports = function httpAdapter(config) {
172
216
 
173
217
  // make sure the content length is not over the maxContentLength if specified
174
218
  if (config.maxContentLength > -1 && Buffer.concat(responseBuffer).length > config.maxContentLength) {
219
+ stream.destroy();
175
220
  reject(createError('maxContentLength size of ' + config.maxContentLength + ' exceeded',
176
221
  config, null, lastRequest));
177
222
  }
@@ -185,7 +230,7 @@ module.exports = function httpAdapter(config) {
185
230
  stream.on('end', function handleStreamEnd() {
186
231
  var responseData = Buffer.concat(responseBuffer);
187
232
  if (config.responseType !== 'arraybuffer') {
188
- responseData = responseData.toString('utf8');
233
+ responseData = responseData.toString(config.responseEncoding);
189
234
  }
190
235
 
191
236
  response.data = responseData;
@@ -201,7 +246,7 @@ module.exports = function httpAdapter(config) {
201
246
  });
202
247
 
203
248
  // Handle request timeout
204
- if (config.timeout && !timer) {
249
+ if (config.timeout) {
205
250
  timer = setTimeout(function handleRequestTimeout() {
206
251
  req.abort();
207
252
  reject(createError('timeout of ' + config.timeout + 'ms exceeded', config, 'ECONNABORTED', req));
@@ -220,7 +265,9 @@ module.exports = function httpAdapter(config) {
220
265
 
221
266
  // Send the request
222
267
  if (utils.isStream(data)) {
223
- data.pipe(req);
268
+ data.on('error', function handleStreamError(err) {
269
+ reject(enhanceError(err, config, null, req));
270
+ }).pipe(req);
224
271
  } else {
225
272
  req.end(data);
226
273
  }
@@ -6,7 +6,6 @@ var buildURL = require('./../helpers/buildURL');
6
6
  var parseHeaders = require('./../helpers/parseHeaders');
7
7
  var isURLSameOrigin = require('./../helpers/isURLSameOrigin');
8
8
  var createError = require('../core/createError');
9
- var btoa = (typeof window !== 'undefined' && window.btoa && window.btoa.bind(window)) || require('./../helpers/btoa');
10
9
 
11
10
  module.exports = function xhrAdapter(config) {
12
11
  return new Promise(function dispatchXhrRequest(resolve, reject) {
@@ -18,22 +17,6 @@ module.exports = function xhrAdapter(config) {
18
17
  }
19
18
 
20
19
  var request = new XMLHttpRequest();
21
- var loadEvent = 'onreadystatechange';
22
- var xDomain = false;
23
-
24
- // For IE 8/9 CORS support
25
- // Only supports POST and GET calls and doesn't returns the response headers.
26
- // DON'T do this for testing b/c XMLHttpRequest is mocked, not XDomainRequest.
27
- if (process.env.NODE_ENV !== 'test' &&
28
- typeof window !== 'undefined' &&
29
- window.XDomainRequest && !('withCredentials' in request) &&
30
- !isURLSameOrigin(config.url)) {
31
- request = new window.XDomainRequest();
32
- loadEvent = 'onload';
33
- xDomain = true;
34
- request.onprogress = function handleProgress() {};
35
- request.ontimeout = function handleTimeout() {};
36
- }
37
20
 
38
21
  // HTTP basic authentication
39
22
  if (config.auth) {
@@ -48,8 +31,8 @@ module.exports = function xhrAdapter(config) {
48
31
  request.timeout = config.timeout;
49
32
 
50
33
  // Listen for ready state
51
- request[loadEvent] = function handleLoad() {
52
- if (!request || (request.readyState !== 4 && !xDomain)) {
34
+ request.onreadystatechange = function handleLoad() {
35
+ if (!request || request.readyState !== 4) {
53
36
  return;
54
37
  }
55
38
 
@@ -66,9 +49,8 @@ module.exports = function xhrAdapter(config) {
66
49
  var responseData = !config.responseType || config.responseType === 'text' ? request.responseText : request.response;
67
50
  var response = {
68
51
  data: responseData,
69
- // IE sends 1223 instead of 204 (https://github.com/axios/axios/issues/201)
70
- status: request.status === 1223 ? 204 : request.status,
71
- statusText: request.status === 1223 ? 'No Content' : request.statusText,
52
+ status: request.status,
53
+ statusText: request.statusText,
72
54
  headers: responseHeaders,
73
55
  config: config,
74
56
  request: request
@@ -80,6 +62,18 @@ module.exports = function xhrAdapter(config) {
80
62
  request = null;
81
63
  };
82
64
 
65
+ // Handle browser request cancellation (as opposed to a manual cancellation)
66
+ request.onabort = function handleAbort() {
67
+ if (!request) {
68
+ return;
69
+ }
70
+
71
+ reject(createError('Request aborted', config, 'ECONNABORTED', request));
72
+
73
+ // Clean up request
74
+ request = null;
75
+ };
76
+
83
77
  // Handle low level network errors
84
78
  request.onerror = function handleError() {
85
79
  // Real errors are hidden from us by the browser
@@ -107,8 +101,8 @@ module.exports = function xhrAdapter(config) {
107
101
 
108
102
  // Add xsrf header
109
103
  var xsrfValue = (config.withCredentials || isURLSameOrigin(config.url)) && config.xsrfCookieName ?
110
- cookies.read(config.xsrfCookieName) :
111
- undefined;
104
+ cookies.read(config.xsrfCookieName) :
105
+ undefined;
112
106
 
113
107
  if (xsrfValue) {
114
108
  requestHeaders[config.xsrfHeaderName] = xsrfValue;
package/lib/axios.js CHANGED
@@ -3,6 +3,7 @@
3
3
  var utils = require('./utils');
4
4
  var bind = require('./helpers/bind');
5
5
  var Axios = require('./core/Axios');
6
+ var mergeConfig = require('./core/mergeConfig');
6
7
  var defaults = require('./defaults');
7
8
 
8
9
  /**
@@ -32,7 +33,7 @@ axios.Axios = Axios;
32
33
 
33
34
  // Factory for creating new instances
34
35
  axios.create = function create(instanceConfig) {
35
- return createInstance(utils.merge(defaults, instanceConfig));
36
+ return createInstance(mergeConfig(axios.defaults, instanceConfig));
36
37
  };
37
38
 
38
39
  // Expose Cancel & CancelToken
package/lib/core/Axios.js CHANGED
@@ -1,9 +1,10 @@
1
1
  'use strict';
2
2
 
3
- var defaults = require('./../defaults');
4
3
  var utils = require('./../utils');
4
+ var buildURL = require('../helpers/buildURL');
5
5
  var InterceptorManager = require('./InterceptorManager');
6
6
  var dispatchRequest = require('./dispatchRequest');
7
+ var mergeConfig = require('./mergeConfig');
7
8
 
8
9
  /**
9
10
  * Create a new instance of Axios
@@ -27,13 +28,14 @@ Axios.prototype.request = function request(config) {
27
28
  /*eslint no-param-reassign:0*/
28
29
  // Allow for axios('example/url'[, config]) a la fetch API
29
30
  if (typeof config === 'string') {
30
- config = utils.merge({
31
- url: arguments[0]
32
- }, arguments[1]);
31
+ config = arguments[1] || {};
32
+ config.url = arguments[0];
33
+ } else {
34
+ config = config || {};
33
35
  }
34
36
 
35
- config = utils.merge(defaults, this.defaults, { method: 'get' }, config);
36
- config.method = config.method.toLowerCase();
37
+ config = mergeConfig(this.defaults, config);
38
+ config.method = config.method ? config.method.toLowerCase() : 'get';
37
39
 
38
40
  // Hook up interceptors middleware
39
41
  var chain = [dispatchRequest, undefined];
@@ -54,6 +56,11 @@ Axios.prototype.request = function request(config) {
54
56
  return promise;
55
57
  };
56
58
 
59
+ Axios.prototype.getUri = function getUri(config) {
60
+ config = mergeConfig(this.defaults, config);
61
+ return buildURL(config.url, config.params, config.paramsSerializer).replace(/^\?/, '');
62
+ };
63
+
57
64
  // Provide aliases for supported request methods
58
65
  utils.forEach(['delete', 'get', 'head', 'options'], function forEachMethodNoData(method) {
59
66
  /*eslint func-names:0*/
@@ -15,7 +15,28 @@ module.exports = function enhanceError(error, config, code, request, response) {
15
15
  if (code) {
16
16
  error.code = code;
17
17
  }
18
+
18
19
  error.request = request;
19
20
  error.response = response;
21
+ error.isAxiosError = true;
22
+
23
+ error.toJSON = function() {
24
+ return {
25
+ // Standard
26
+ message: this.message,
27
+ name: this.name,
28
+ // Microsoft
29
+ description: this.description,
30
+ number: this.number,
31
+ // Mozilla
32
+ fileName: this.fileName,
33
+ lineNumber: this.lineNumber,
34
+ columnNumber: this.columnNumber,
35
+ stack: this.stack,
36
+ // Axios
37
+ config: this.config,
38
+ code: this.code
39
+ };
40
+ };
20
41
  return error;
21
42
  };
@@ -0,0 +1,51 @@
1
+ 'use strict';
2
+
3
+ var utils = require('../utils');
4
+
5
+ /**
6
+ * Config-specific merge-function which creates a new config-object
7
+ * by merging two configuration objects together.
8
+ *
9
+ * @param {Object} config1
10
+ * @param {Object} config2
11
+ * @returns {Object} New object resulting from merging config2 to config1
12
+ */
13
+ module.exports = function mergeConfig(config1, config2) {
14
+ // eslint-disable-next-line no-param-reassign
15
+ config2 = config2 || {};
16
+ var config = {};
17
+
18
+ utils.forEach(['url', 'method', 'params', 'data'], function valueFromConfig2(prop) {
19
+ if (typeof config2[prop] !== 'undefined') {
20
+ config[prop] = config2[prop];
21
+ }
22
+ });
23
+
24
+ utils.forEach(['headers', 'auth', 'proxy'], function mergeDeepProperties(prop) {
25
+ if (utils.isObject(config2[prop])) {
26
+ config[prop] = utils.deepMerge(config1[prop], config2[prop]);
27
+ } else if (typeof config2[prop] !== 'undefined') {
28
+ config[prop] = config2[prop];
29
+ } else if (utils.isObject(config1[prop])) {
30
+ config[prop] = utils.deepMerge(config1[prop]);
31
+ } else if (typeof config1[prop] !== 'undefined') {
32
+ config[prop] = config1[prop];
33
+ }
34
+ });
35
+
36
+ utils.forEach([
37
+ 'baseURL', 'transformRequest', 'transformResponse', 'paramsSerializer',
38
+ 'timeout', 'withCredentials', 'adapter', 'responseType', 'xsrfCookieName',
39
+ 'xsrfHeaderName', 'onUploadProgress', 'onDownloadProgress', 'maxContentLength',
40
+ 'validateStatus', 'maxRedirects', 'httpAgent', 'httpsAgent', 'cancelToken',
41
+ 'socketPath'
42
+ ], function defaultToConfig2(prop) {
43
+ if (typeof config2[prop] !== 'undefined') {
44
+ config[prop] = config2[prop];
45
+ } else if (typeof config1[prop] !== 'undefined') {
46
+ config[prop] = config1[prop];
47
+ }
48
+ });
49
+
50
+ return config;
51
+ };
@@ -11,8 +11,7 @@ var createError = require('./createError');
11
11
  */
12
12
  module.exports = function settle(resolve, reject, response) {
13
13
  var validateStatus = response.config.validateStatus;
14
- // Note: status is not exposed by XDomainRequest
15
- if (!response.status || !validateStatus || validateStatus(response.status)) {
14
+ if (!validateStatus || validateStatus(response.status)) {
16
15
  resolve(response);
17
16
  } else {
18
17
  reject(createError(
package/lib/defaults.js CHANGED
@@ -15,12 +15,13 @@ function setContentTypeIfUnset(headers, value) {
15
15
 
16
16
  function getDefaultAdapter() {
17
17
  var adapter;
18
- if (typeof XMLHttpRequest !== 'undefined') {
19
- // For browsers use XHR adapter
20
- adapter = require('./adapters/xhr');
21
- } else if (typeof process !== 'undefined') {
18
+ // Only Node.JS has a process variable that is of [[Class]] process
19
+ if (typeof process !== 'undefined' && Object.prototype.toString.call(process) === '[object process]') {
22
20
  // For node use HTTP adapter
23
21
  adapter = require('./adapters/http');
22
+ } else if (typeof XMLHttpRequest !== 'undefined') {
23
+ // For browsers use XHR adapter
24
+ adapter = require('./adapters/xhr');
24
25
  }
25
26
  return adapter;
26
27
  }
@@ -29,6 +30,7 @@ var defaults = {
29
30
  adapter: getDefaultAdapter(),
30
31
 
31
32
  transformRequest: [function transformRequest(data, headers) {
33
+ normalizeHeaderName(headers, 'Accept');
32
34
  normalizeHeaderName(headers, 'Content-Type');
33
35
  if (utils.isFormData(data) ||
34
36
  utils.isArrayBuffer(data) ||
@@ -63,6 +65,10 @@ var defaults = {
63
65
  return data;
64
66
  }],
65
67
 
68
+ /**
69
+ * A timeout in milliseconds to abort a request. If set to 0 (default) a
70
+ * timeout is not created.
71
+ */
66
72
  timeout: 0,
67
73
 
68
74
  xsrfCookieName: 'XSRF-TOKEN',
@@ -41,9 +41,7 @@ module.exports = function buildURL(url, params, paramsSerializer) {
41
41
 
42
42
  if (utils.isArray(val)) {
43
43
  key = key + '[]';
44
- }
45
-
46
- if (!utils.isArray(val)) {
44
+ } else {
47
45
  val = [val];
48
46
  }
49
47
 
@@ -61,6 +59,11 @@ module.exports = function buildURL(url, params, paramsSerializer) {
61
59
  }
62
60
 
63
61
  if (serializedParams) {
62
+ var hashmarkIndex = url.indexOf('#');
63
+ if (hashmarkIndex !== -1) {
64
+ url = url.slice(0, hashmarkIndex);
65
+ }
66
+
64
67
  url += (url.indexOf('?') === -1 ? '?' : '&') + serializedParams;
65
68
  }
66
69