mirror of
https://github.com/notherealmarco/WASAPhoto.git
synced 2025-05-06 04:42:36 +02:00
Add decaf webui
This commit is contained in:
parent
6b4c9bb531
commit
69c0388954
742 changed files with 608981 additions and 6 deletions
37
webui/node_modules/axios/lib/adapters/README.md
generated
vendored
Normal file
37
webui/node_modules/axios/lib/adapters/README.md
generated
vendored
Normal file
|
@ -0,0 +1,37 @@
|
|||
# axios // adapters
|
||||
|
||||
The modules under `adapters/` are modules that handle dispatching a request and settling a returned `Promise` once a response is received.
|
||||
|
||||
## Example
|
||||
|
||||
```js
|
||||
var settle = require('./../core/settle');
|
||||
|
||||
module.exports = function myAdapter(config) {
|
||||
// At this point:
|
||||
// - config has been merged with defaults
|
||||
// - request transformers have already run
|
||||
// - request interceptors have already run
|
||||
|
||||
// Make the request using config provided
|
||||
// Upon response settle the Promise
|
||||
|
||||
return new Promise(function(resolve, reject) {
|
||||
|
||||
var response = {
|
||||
data: responseData,
|
||||
status: request.status,
|
||||
statusText: request.statusText,
|
||||
headers: responseHeaders,
|
||||
config: config,
|
||||
request: request
|
||||
};
|
||||
|
||||
settle(resolve, reject, response);
|
||||
|
||||
// From here:
|
||||
// - response transformers will run
|
||||
// - response interceptors will run
|
||||
});
|
||||
}
|
||||
```
|
424
webui/node_modules/axios/lib/adapters/http.js
generated
vendored
Executable file
424
webui/node_modules/axios/lib/adapters/http.js
generated
vendored
Executable file
|
@ -0,0 +1,424 @@
|
|||
'use strict';
|
||||
|
||||
var utils = require('./../utils');
|
||||
var settle = require('./../core/settle');
|
||||
var buildFullPath = require('../core/buildFullPath');
|
||||
var buildURL = require('./../helpers/buildURL');
|
||||
var http = require('http');
|
||||
var https = require('https');
|
||||
var httpFollow = require('follow-redirects').http;
|
||||
var httpsFollow = require('follow-redirects').https;
|
||||
var url = require('url');
|
||||
var zlib = require('zlib');
|
||||
var VERSION = require('./../env/data').version;
|
||||
var transitionalDefaults = require('../defaults/transitional');
|
||||
var AxiosError = require('../core/AxiosError');
|
||||
var CanceledError = require('../cancel/CanceledError');
|
||||
|
||||
var isHttps = /https:?/;
|
||||
|
||||
var supportedProtocols = [ 'http:', 'https:', 'file:' ];
|
||||
|
||||
/**
|
||||
*
|
||||
* @param {http.ClientRequestArgs} options
|
||||
* @param {AxiosProxyConfig} proxy
|
||||
* @param {string} location
|
||||
*/
|
||||
function setProxy(options, proxy, location) {
|
||||
options.hostname = proxy.host;
|
||||
options.host = proxy.host;
|
||||
options.port = proxy.port;
|
||||
options.path = location;
|
||||
|
||||
// Basic proxy authorization
|
||||
if (proxy.auth) {
|
||||
var base64 = Buffer.from(proxy.auth.username + ':' + proxy.auth.password, 'utf8').toString('base64');
|
||||
options.headers['Proxy-Authorization'] = 'Basic ' + base64;
|
||||
}
|
||||
|
||||
// If a proxy is used, any redirects must also pass through the proxy
|
||||
options.beforeRedirect = function beforeRedirect(redirection) {
|
||||
redirection.headers.host = redirection.host;
|
||||
setProxy(redirection, proxy, redirection.href);
|
||||
};
|
||||
}
|
||||
|
||||
/*eslint consistent-return:0*/
|
||||
module.exports = function httpAdapter(config) {
|
||||
return new Promise(function dispatchHttpRequest(resolvePromise, rejectPromise) {
|
||||
var onCanceled;
|
||||
function done() {
|
||||
if (config.cancelToken) {
|
||||
config.cancelToken.unsubscribe(onCanceled);
|
||||
}
|
||||
|
||||
if (config.signal) {
|
||||
config.signal.removeEventListener('abort', onCanceled);
|
||||
}
|
||||
}
|
||||
var resolve = function resolve(value) {
|
||||
done();
|
||||
resolvePromise(value);
|
||||
};
|
||||
var rejected = false;
|
||||
var reject = function reject(value) {
|
||||
done();
|
||||
rejected = true;
|
||||
rejectPromise(value);
|
||||
};
|
||||
var data = config.data;
|
||||
var headers = config.headers;
|
||||
var headerNames = {};
|
||||
|
||||
Object.keys(headers).forEach(function storeLowerName(name) {
|
||||
headerNames[name.toLowerCase()] = name;
|
||||
});
|
||||
|
||||
// Set User-Agent (required by some servers)
|
||||
// See https://github.com/axios/axios/issues/69
|
||||
if ('user-agent' in headerNames) {
|
||||
// User-Agent is specified; handle case where no UA header is desired
|
||||
if (!headers[headerNames['user-agent']]) {
|
||||
delete headers[headerNames['user-agent']];
|
||||
}
|
||||
// Otherwise, use specified value
|
||||
} else {
|
||||
// Only set header if it hasn't been set in config
|
||||
headers['User-Agent'] = 'axios/' + VERSION;
|
||||
}
|
||||
|
||||
// support for https://www.npmjs.com/package/form-data api
|
||||
if (utils.isFormData(data) && utils.isFunction(data.getHeaders)) {
|
||||
Object.assign(headers, data.getHeaders());
|
||||
} else if (data && !utils.isStream(data)) {
|
||||
if (Buffer.isBuffer(data)) {
|
||||
// Nothing to do...
|
||||
} else if (utils.isArrayBuffer(data)) {
|
||||
data = Buffer.from(new Uint8Array(data));
|
||||
} else if (utils.isString(data)) {
|
||||
data = Buffer.from(data, 'utf-8');
|
||||
} else {
|
||||
return reject(new AxiosError(
|
||||
'Data after transformation must be a string, an ArrayBuffer, a Buffer, or a Stream',
|
||||
AxiosError.ERR_BAD_REQUEST,
|
||||
config
|
||||
));
|
||||
}
|
||||
|
||||
if (config.maxBodyLength > -1 && data.length > config.maxBodyLength) {
|
||||
return reject(new AxiosError(
|
||||
'Request body larger than maxBodyLength limit',
|
||||
AxiosError.ERR_BAD_REQUEST,
|
||||
config
|
||||
));
|
||||
}
|
||||
|
||||
// Add Content-Length header if data exists
|
||||
if (!headerNames['content-length']) {
|
||||
headers['Content-Length'] = data.length;
|
||||
}
|
||||
}
|
||||
|
||||
// HTTP basic authentication
|
||||
var auth = undefined;
|
||||
if (config.auth) {
|
||||
var username = config.auth.username || '';
|
||||
var password = config.auth.password || '';
|
||||
auth = username + ':' + password;
|
||||
}
|
||||
|
||||
// Parse url
|
||||
var fullPath = buildFullPath(config.baseURL, config.url);
|
||||
var parsed = url.parse(fullPath);
|
||||
var protocol = parsed.protocol || supportedProtocols[0];
|
||||
|
||||
if (supportedProtocols.indexOf(protocol) === -1) {
|
||||
return reject(new AxiosError(
|
||||
'Unsupported protocol ' + protocol,
|
||||
AxiosError.ERR_BAD_REQUEST,
|
||||
config
|
||||
));
|
||||
}
|
||||
|
||||
if (!auth && parsed.auth) {
|
||||
var urlAuth = parsed.auth.split(':');
|
||||
var urlUsername = urlAuth[0] || '';
|
||||
var urlPassword = urlAuth[1] || '';
|
||||
auth = urlUsername + ':' + urlPassword;
|
||||
}
|
||||
|
||||
if (auth && headerNames.authorization) {
|
||||
delete headers[headerNames.authorization];
|
||||
}
|
||||
|
||||
var isHttpsRequest = isHttps.test(protocol);
|
||||
var agent = isHttpsRequest ? config.httpsAgent : config.httpAgent;
|
||||
|
||||
try {
|
||||
buildURL(parsed.path, config.params, config.paramsSerializer).replace(/^\?/, '');
|
||||
} catch (err) {
|
||||
var customErr = new Error(err.message);
|
||||
customErr.config = config;
|
||||
customErr.url = config.url;
|
||||
customErr.exists = true;
|
||||
reject(customErr);
|
||||
}
|
||||
|
||||
var options = {
|
||||
path: buildURL(parsed.path, config.params, config.paramsSerializer).replace(/^\?/, ''),
|
||||
method: config.method.toUpperCase(),
|
||||
headers: headers,
|
||||
agent: agent,
|
||||
agents: { http: config.httpAgent, https: config.httpsAgent },
|
||||
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';
|
||||
var proxyUrl = process.env[proxyEnv] || process.env[proxyEnv.toUpperCase()];
|
||||
if (proxyUrl) {
|
||||
var parsedProxyUrl = url.parse(proxyUrl);
|
||||
var noProxyEnv = process.env.no_proxy || process.env.NO_PROXY;
|
||||
var shouldProxy = true;
|
||||
|
||||
if (noProxyEnv) {
|
||||
var noProxy = noProxyEnv.split(',').map(function trim(s) {
|
||||
return s.trim();
|
||||
});
|
||||
|
||||
shouldProxy = !noProxy.some(function proxyMatch(proxyElement) {
|
||||
if (!proxyElement) {
|
||||
return false;
|
||||
}
|
||||
if (proxyElement === '*') {
|
||||
return true;
|
||||
}
|
||||
if (proxyElement[0] === '.' &&
|
||||
parsed.hostname.substr(parsed.hostname.length - proxyElement.length) === proxyElement) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return parsed.hostname === proxyElement;
|
||||
});
|
||||
}
|
||||
|
||||
if (shouldProxy) {
|
||||
proxy = {
|
||||
host: parsedProxyUrl.hostname,
|
||||
port: parsedProxyUrl.port,
|
||||
protocol: parsedProxyUrl.protocol
|
||||
};
|
||||
|
||||
if (parsedProxyUrl.auth) {
|
||||
var proxyUrlAuth = parsedProxyUrl.auth.split(':');
|
||||
proxy.auth = {
|
||||
username: proxyUrlAuth[0],
|
||||
password: proxyUrlAuth[1]
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (proxy) {
|
||||
options.headers.host = parsed.hostname + (parsed.port ? ':' + parsed.port : '');
|
||||
setProxy(options, proxy, protocol + '//' + parsed.hostname + (parsed.port ? ':' + parsed.port : '') + options.path);
|
||||
}
|
||||
|
||||
var transport;
|
||||
var isHttpsProxy = isHttpsRequest && (proxy ? isHttps.test(proxy.protocol) : true);
|
||||
if (config.transport) {
|
||||
transport = config.transport;
|
||||
} else if (config.maxRedirects === 0) {
|
||||
transport = isHttpsProxy ? https : http;
|
||||
} else {
|
||||
if (config.maxRedirects) {
|
||||
options.maxRedirects = config.maxRedirects;
|
||||
}
|
||||
if (config.beforeRedirect) {
|
||||
options.beforeRedirect = config.beforeRedirect;
|
||||
}
|
||||
transport = isHttpsProxy ? httpsFollow : httpFollow;
|
||||
}
|
||||
|
||||
if (config.maxBodyLength > -1) {
|
||||
options.maxBodyLength = config.maxBodyLength;
|
||||
}
|
||||
|
||||
if (config.insecureHTTPParser) {
|
||||
options.insecureHTTPParser = config.insecureHTTPParser;
|
||||
}
|
||||
|
||||
// Create the request
|
||||
var req = transport.request(options, function handleResponse(res) {
|
||||
if (req.aborted) return;
|
||||
|
||||
// uncompress the response body transparently if required
|
||||
var stream = res;
|
||||
|
||||
// return the last request in case of redirects
|
||||
var lastRequest = res.req || req;
|
||||
|
||||
|
||||
// if no content, is HEAD request or decompress disabled we should not decompress
|
||||
if (res.statusCode !== 204 && lastRequest.method !== 'HEAD' && config.decompress !== false) {
|
||||
switch (res.headers['content-encoding']) {
|
||||
/*eslint default-case:0*/
|
||||
case 'gzip':
|
||||
case 'compress':
|
||||
case 'deflate':
|
||||
// add the unzipper to the body stream processing pipeline
|
||||
stream = stream.pipe(zlib.createUnzip());
|
||||
|
||||
// remove the content-encoding in order to not confuse downstream operations
|
||||
delete res.headers['content-encoding'];
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
var response = {
|
||||
status: res.statusCode,
|
||||
statusText: res.statusMessage,
|
||||
headers: res.headers,
|
||||
config: config,
|
||||
request: lastRequest
|
||||
};
|
||||
|
||||
if (config.responseType === 'stream') {
|
||||
response.data = stream;
|
||||
settle(resolve, reject, response);
|
||||
} else {
|
||||
var responseBuffer = [];
|
||||
var totalResponseBytes = 0;
|
||||
stream.on('data', function handleStreamData(chunk) {
|
||||
responseBuffer.push(chunk);
|
||||
totalResponseBytes += chunk.length;
|
||||
|
||||
// make sure the content length is not over the maxContentLength if specified
|
||||
if (config.maxContentLength > -1 && totalResponseBytes > config.maxContentLength) {
|
||||
// stream.destoy() emit aborted event before calling reject() on Node.js v16
|
||||
rejected = true;
|
||||
stream.destroy();
|
||||
reject(new AxiosError('maxContentLength size of ' + config.maxContentLength + ' exceeded',
|
||||
AxiosError.ERR_BAD_RESPONSE, config, lastRequest));
|
||||
}
|
||||
});
|
||||
|
||||
stream.on('aborted', function handlerStreamAborted() {
|
||||
if (rejected) {
|
||||
return;
|
||||
}
|
||||
stream.destroy();
|
||||
reject(new AxiosError(
|
||||
'maxContentLength size of ' + config.maxContentLength + ' exceeded',
|
||||
AxiosError.ERR_BAD_RESPONSE,
|
||||
config,
|
||||
lastRequest
|
||||
));
|
||||
});
|
||||
|
||||
stream.on('error', function handleStreamError(err) {
|
||||
if (req.aborted) return;
|
||||
reject(AxiosError.from(err, null, config, lastRequest));
|
||||
});
|
||||
|
||||
stream.on('end', function handleStreamEnd() {
|
||||
try {
|
||||
var responseData = responseBuffer.length === 1 ? responseBuffer[0] : Buffer.concat(responseBuffer);
|
||||
if (config.responseType !== 'arraybuffer') {
|
||||
responseData = responseData.toString(config.responseEncoding);
|
||||
if (!config.responseEncoding || config.responseEncoding === 'utf8') {
|
||||
responseData = utils.stripBOM(responseData);
|
||||
}
|
||||
}
|
||||
response.data = responseData;
|
||||
} catch (err) {
|
||||
reject(AxiosError.from(err, null, config, response.request, response));
|
||||
}
|
||||
settle(resolve, reject, response);
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
// Handle errors
|
||||
req.on('error', function handleRequestError(err) {
|
||||
// @todo remove
|
||||
// if (req.aborted && err.code !== AxiosError.ERR_FR_TOO_MANY_REDIRECTS) return;
|
||||
reject(AxiosError.from(err, null, config, req));
|
||||
});
|
||||
|
||||
// set tcp keep alive to prevent drop connection by peer
|
||||
req.on('socket', function handleRequestSocket(socket) {
|
||||
// default interval of sending ack packet is 1 minute
|
||||
socket.setKeepAlive(true, 1000 * 60);
|
||||
});
|
||||
|
||||
// Handle request timeout
|
||||
if (config.timeout) {
|
||||
// This is forcing a int timeout to avoid problems if the `req` interface doesn't handle other types.
|
||||
var timeout = parseInt(config.timeout, 10);
|
||||
|
||||
if (isNaN(timeout)) {
|
||||
reject(new AxiosError(
|
||||
'error trying to parse `config.timeout` to int',
|
||||
AxiosError.ERR_BAD_OPTION_VALUE,
|
||||
config,
|
||||
req
|
||||
));
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
// Sometime, the response will be very slow, and does not respond, the connect event will be block by event loop system.
|
||||
// And timer callback will be fired, and abort() will be invoked before connection, then get "socket hang up" and code ECONNRESET.
|
||||
// At this time, if we have a large number of request, nodejs will hang up some socket on background. and the number will up and up.
|
||||
// And then these socket which be hang up will devoring CPU little by little.
|
||||
// ClientRequest.setTimeout will be fired on the specify milliseconds, and can make sure that abort() will be fired after connect.
|
||||
req.setTimeout(timeout, function handleRequestTimeout() {
|
||||
req.abort();
|
||||
var transitional = config.transitional || transitionalDefaults;
|
||||
reject(new AxiosError(
|
||||
'timeout of ' + timeout + 'ms exceeded',
|
||||
transitional.clarifyTimeoutError ? AxiosError.ETIMEDOUT : AxiosError.ECONNABORTED,
|
||||
config,
|
||||
req
|
||||
));
|
||||
});
|
||||
}
|
||||
|
||||
if (config.cancelToken || config.signal) {
|
||||
// Handle cancellation
|
||||
// eslint-disable-next-line func-names
|
||||
onCanceled = function(cancel) {
|
||||
if (req.aborted) return;
|
||||
|
||||
req.abort();
|
||||
reject(!cancel || (cancel && cancel.type) ? new CanceledError() : cancel);
|
||||
};
|
||||
|
||||
config.cancelToken && config.cancelToken.subscribe(onCanceled);
|
||||
if (config.signal) {
|
||||
config.signal.aborted ? onCanceled() : config.signal.addEventListener('abort', onCanceled);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// Send the request
|
||||
if (utils.isStream(data)) {
|
||||
data.on('error', function handleStreamError(err) {
|
||||
reject(AxiosError.from(err, config, null, req));
|
||||
}).pipe(req);
|
||||
} else {
|
||||
req.end(data);
|
||||
}
|
||||
});
|
||||
};
|
222
webui/node_modules/axios/lib/adapters/xhr.js
generated
vendored
Normal file
222
webui/node_modules/axios/lib/adapters/xhr.js
generated
vendored
Normal file
|
@ -0,0 +1,222 @@
|
|||
'use strict';
|
||||
|
||||
var utils = require('./../utils');
|
||||
var settle = require('./../core/settle');
|
||||
var cookies = require('./../helpers/cookies');
|
||||
var buildURL = require('./../helpers/buildURL');
|
||||
var buildFullPath = require('../core/buildFullPath');
|
||||
var parseHeaders = require('./../helpers/parseHeaders');
|
||||
var isURLSameOrigin = require('./../helpers/isURLSameOrigin');
|
||||
var transitionalDefaults = require('../defaults/transitional');
|
||||
var AxiosError = require('../core/AxiosError');
|
||||
var CanceledError = require('../cancel/CanceledError');
|
||||
var parseProtocol = require('../helpers/parseProtocol');
|
||||
|
||||
module.exports = function xhrAdapter(config) {
|
||||
return new Promise(function dispatchXhrRequest(resolve, reject) {
|
||||
var requestData = config.data;
|
||||
var requestHeaders = config.headers;
|
||||
var responseType = config.responseType;
|
||||
var onCanceled;
|
||||
function done() {
|
||||
if (config.cancelToken) {
|
||||
config.cancelToken.unsubscribe(onCanceled);
|
||||
}
|
||||
|
||||
if (config.signal) {
|
||||
config.signal.removeEventListener('abort', onCanceled);
|
||||
}
|
||||
}
|
||||
|
||||
if (utils.isFormData(requestData) && utils.isStandardBrowserEnv()) {
|
||||
delete requestHeaders['Content-Type']; // Let the browser set it
|
||||
}
|
||||
|
||||
var request = new XMLHttpRequest();
|
||||
|
||||
// HTTP basic authentication
|
||||
if (config.auth) {
|
||||
var username = config.auth.username || '';
|
||||
var password = config.auth.password ? unescape(encodeURIComponent(config.auth.password)) : '';
|
||||
requestHeaders.Authorization = 'Basic ' + btoa(username + ':' + password);
|
||||
}
|
||||
|
||||
var fullPath = buildFullPath(config.baseURL, config.url);
|
||||
|
||||
request.open(config.method.toUpperCase(), buildURL(fullPath, config.params, config.paramsSerializer), true);
|
||||
|
||||
// Set the request timeout in MS
|
||||
request.timeout = config.timeout;
|
||||
|
||||
function onloadend() {
|
||||
if (!request) {
|
||||
return;
|
||||
}
|
||||
// Prepare the response
|
||||
var responseHeaders = 'getAllResponseHeaders' in request ? parseHeaders(request.getAllResponseHeaders()) : null;
|
||||
var responseData = !responseType || responseType === 'text' || responseType === 'json' ?
|
||||
request.responseText : request.response;
|
||||
var response = {
|
||||
data: responseData,
|
||||
status: request.status,
|
||||
statusText: request.statusText,
|
||||
headers: responseHeaders,
|
||||
config: config,
|
||||
request: request
|
||||
};
|
||||
|
||||
settle(function _resolve(value) {
|
||||
resolve(value);
|
||||
done();
|
||||
}, function _reject(err) {
|
||||
reject(err);
|
||||
done();
|
||||
}, response);
|
||||
|
||||
// Clean up request
|
||||
request = null;
|
||||
}
|
||||
|
||||
if ('onloadend' in request) {
|
||||
// Use onloadend if available
|
||||
request.onloadend = onloadend;
|
||||
} else {
|
||||
// Listen for ready state to emulate onloadend
|
||||
request.onreadystatechange = function handleLoad() {
|
||||
if (!request || request.readyState !== 4) {
|
||||
return;
|
||||
}
|
||||
|
||||
// The request errored out and we didn't get a response, this will be
|
||||
// handled by onerror instead
|
||||
// With one exception: request that using file: protocol, most browsers
|
||||
// will return status as 0 even though it's a successful request
|
||||
if (request.status === 0 && !(request.responseURL && request.responseURL.indexOf('file:') === 0)) {
|
||||
return;
|
||||
}
|
||||
// readystate handler is calling before onerror or ontimeout handlers,
|
||||
// so we should call onloadend on the next 'tick'
|
||||
setTimeout(onloadend);
|
||||
};
|
||||
}
|
||||
|
||||
// Handle browser request cancellation (as opposed to a manual cancellation)
|
||||
request.onabort = function handleAbort() {
|
||||
if (!request) {
|
||||
return;
|
||||
}
|
||||
|
||||
reject(new AxiosError('Request aborted', AxiosError.ECONNABORTED, config, request));
|
||||
|
||||
// Clean up request
|
||||
request = null;
|
||||
};
|
||||
|
||||
// Handle low level network errors
|
||||
request.onerror = function handleError() {
|
||||
// Real errors are hidden from us by the browser
|
||||
// onerror should only fire if it's a network error
|
||||
reject(new AxiosError('Network Error', AxiosError.ERR_NETWORK, config, request, request));
|
||||
|
||||
// Clean up request
|
||||
request = null;
|
||||
};
|
||||
|
||||
// Handle timeout
|
||||
request.ontimeout = function handleTimeout() {
|
||||
var timeoutErrorMessage = config.timeout ? 'timeout of ' + config.timeout + 'ms exceeded' : 'timeout exceeded';
|
||||
var transitional = config.transitional || transitionalDefaults;
|
||||
if (config.timeoutErrorMessage) {
|
||||
timeoutErrorMessage = config.timeoutErrorMessage;
|
||||
}
|
||||
reject(new AxiosError(
|
||||
timeoutErrorMessage,
|
||||
transitional.clarifyTimeoutError ? AxiosError.ETIMEDOUT : AxiosError.ECONNABORTED,
|
||||
config,
|
||||
request));
|
||||
|
||||
// Clean up request
|
||||
request = null;
|
||||
};
|
||||
|
||||
// Add xsrf header
|
||||
// This is only done if running in a standard browser environment.
|
||||
// Specifically not if we're in a web worker, or react-native.
|
||||
if (utils.isStandardBrowserEnv()) {
|
||||
// Add xsrf header
|
||||
var xsrfValue = (config.withCredentials || isURLSameOrigin(fullPath)) && config.xsrfCookieName ?
|
||||
cookies.read(config.xsrfCookieName) :
|
||||
undefined;
|
||||
|
||||
if (xsrfValue) {
|
||||
requestHeaders[config.xsrfHeaderName] = xsrfValue;
|
||||
}
|
||||
}
|
||||
|
||||
// Add headers to the request
|
||||
if ('setRequestHeader' in request) {
|
||||
utils.forEach(requestHeaders, function setRequestHeader(val, key) {
|
||||
if (typeof requestData === 'undefined' && key.toLowerCase() === 'content-type') {
|
||||
// Remove Content-Type if data is undefined
|
||||
delete requestHeaders[key];
|
||||
} else {
|
||||
// Otherwise add header to the request
|
||||
request.setRequestHeader(key, val);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
// Add withCredentials to request if needed
|
||||
if (!utils.isUndefined(config.withCredentials)) {
|
||||
request.withCredentials = !!config.withCredentials;
|
||||
}
|
||||
|
||||
// Add responseType to request if needed
|
||||
if (responseType && responseType !== 'json') {
|
||||
request.responseType = config.responseType;
|
||||
}
|
||||
|
||||
// Handle progress if needed
|
||||
if (typeof config.onDownloadProgress === 'function') {
|
||||
request.addEventListener('progress', config.onDownloadProgress);
|
||||
}
|
||||
|
||||
// Not all browsers support upload events
|
||||
if (typeof config.onUploadProgress === 'function' && request.upload) {
|
||||
request.upload.addEventListener('progress', config.onUploadProgress);
|
||||
}
|
||||
|
||||
if (config.cancelToken || config.signal) {
|
||||
// Handle cancellation
|
||||
// eslint-disable-next-line func-names
|
||||
onCanceled = function(cancel) {
|
||||
if (!request) {
|
||||
return;
|
||||
}
|
||||
reject(!cancel || (cancel && cancel.type) ? new CanceledError() : cancel);
|
||||
request.abort();
|
||||
request = null;
|
||||
};
|
||||
|
||||
config.cancelToken && config.cancelToken.subscribe(onCanceled);
|
||||
if (config.signal) {
|
||||
config.signal.aborted ? onCanceled() : config.signal.addEventListener('abort', onCanceled);
|
||||
}
|
||||
}
|
||||
|
||||
if (!requestData) {
|
||||
requestData = null;
|
||||
}
|
||||
|
||||
var protocol = parseProtocol(fullPath);
|
||||
|
||||
if (protocol && [ 'http', 'https', 'file' ].indexOf(protocol) === -1) {
|
||||
reject(new AxiosError('Unsupported protocol ' + protocol + ':', AxiosError.ERR_BAD_REQUEST, config));
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
// Send the request
|
||||
request.send(requestData);
|
||||
});
|
||||
};
|
Loading…
Add table
Add a link
Reference in a new issue