mirror of
https://git.mirrors.martin98.com/https://github.com/cyberman54/curl
synced 2026-04-02 08:03:17 +08:00
fix: validate status and some security
This commit is contained in:
62
node_modules/axios/lib/cancel/CancelToken.js
generated
vendored
62
node_modules/axios/lib/cancel/CancelToken.js
generated
vendored
@@ -14,11 +14,42 @@ function CancelToken(executor) {
|
||||
}
|
||||
|
||||
var resolvePromise;
|
||||
|
||||
this.promise = new Promise(function promiseExecutor(resolve) {
|
||||
resolvePromise = resolve;
|
||||
});
|
||||
|
||||
var token = this;
|
||||
|
||||
// eslint-disable-next-line func-names
|
||||
this.promise.then(function(cancel) {
|
||||
if (!token._listeners) return;
|
||||
|
||||
var i;
|
||||
var l = token._listeners.length;
|
||||
|
||||
for (i = 0; i < l; i++) {
|
||||
token._listeners[i](cancel);
|
||||
}
|
||||
token._listeners = null;
|
||||
});
|
||||
|
||||
// eslint-disable-next-line func-names
|
||||
this.promise.then = function(onfulfilled) {
|
||||
var _resolve;
|
||||
// eslint-disable-next-line func-names
|
||||
var promise = new Promise(function(resolve) {
|
||||
token.subscribe(resolve);
|
||||
_resolve = resolve;
|
||||
}).then(onfulfilled);
|
||||
|
||||
promise.cancel = function reject() {
|
||||
token.unsubscribe(_resolve);
|
||||
};
|
||||
|
||||
return promise;
|
||||
};
|
||||
|
||||
executor(function cancel(message) {
|
||||
if (token.reason) {
|
||||
// Cancellation has already been requested
|
||||
@@ -39,6 +70,37 @@ CancelToken.prototype.throwIfRequested = function throwIfRequested() {
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Subscribe to the cancel signal
|
||||
*/
|
||||
|
||||
CancelToken.prototype.subscribe = function subscribe(listener) {
|
||||
if (this.reason) {
|
||||
listener(this.reason);
|
||||
return;
|
||||
}
|
||||
|
||||
if (this._listeners) {
|
||||
this._listeners.push(listener);
|
||||
} else {
|
||||
this._listeners = [listener];
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Unsubscribe from the cancel signal
|
||||
*/
|
||||
|
||||
CancelToken.prototype.unsubscribe = function unsubscribe(listener) {
|
||||
if (!this._listeners) {
|
||||
return;
|
||||
}
|
||||
var index = this._listeners.indexOf(listener);
|
||||
if (index !== -1) {
|
||||
this._listeners.splice(index, 1);
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Returns an object that contains a new `CancelToken` and a function that, when called,
|
||||
* cancels the `CancelToken`.
|
||||
|
||||
Reference in New Issue
Block a user