mirror of
https://github.com/DoctorMcKay/node-steamcommunity.git
synced 2025-02-23 18:30:08 +08:00
Added ability to delay HTTP requests
This commit is contained in:
parent
54b83016af
commit
eed791acbd
@ -22,16 +22,33 @@ SteamCommunity.prototype.httpRequest = function(uri, options, callback, source)
|
|||||||
var requestID = ++this._httpRequestID;
|
var requestID = ++this._httpRequestID;
|
||||||
source = source || "";
|
source = source || "";
|
||||||
|
|
||||||
if (this.onPreHttpRequest && this.onPreHttpRequest(requestID, source, options, callback) === false) {
|
var self = this;
|
||||||
return false;
|
var continued = false;
|
||||||
|
|
||||||
|
if (!this.onPreHttpRequest || !this.onPreHttpRequest(requestID, source, options, continueRequest)) {
|
||||||
|
// No pre-hook, or the pre-hook doesn't want to delay the request.
|
||||||
|
continueRequest(null);
|
||||||
}
|
}
|
||||||
|
|
||||||
var self = this;
|
function continueRequest(err) {
|
||||||
this.request(options, function(err, response, body) {
|
if (continued) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
continued = true;
|
||||||
|
|
||||||
|
if (err) {
|
||||||
|
callback(err);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
self.request(options, function (err, response, body) {
|
||||||
var hasCallback = !!callback;
|
var hasCallback = !!callback;
|
||||||
var httpError = options.checkHttpError !== false && self._checkHttpError(err, response, callback);
|
var httpError = options.checkHttpError !== false && self._checkHttpError(err, response, callback);
|
||||||
var communityError = !options.json && options.checkCommunityError !== false && self._checkCommunityError(body, httpError ? function() {} : callback); // don't fire the callback if hasHttpError did it already
|
var communityError = !options.json && options.checkCommunityError !== false && self._checkCommunityError(body, httpError ? function () {
|
||||||
var tradeError = !options.json && options.checkTradeError !== false && self._checkTradeError(body, httpError || communityError ? function() {} : callback); // don't fire the callback if either of the previous already did
|
} : callback); // don't fire the callback if hasHttpError did it already
|
||||||
|
var tradeError = !options.json && options.checkTradeError !== false && self._checkTradeError(body, httpError || communityError ? function () {
|
||||||
|
} : callback); // don't fire the callback if either of the previous already did
|
||||||
|
|
||||||
self.emit('postHttpRequest', requestID, source, options, httpError || communityError || tradeError || null, response, body, {
|
self.emit('postHttpRequest', requestID, source, options, httpError || communityError || tradeError || null, response, body, {
|
||||||
"hasCallback": hasCallback,
|
"hasCallback": hasCallback,
|
||||||
@ -44,8 +61,7 @@ SteamCommunity.prototype.httpRequest = function(uri, options, callback, source)
|
|||||||
callback.apply(self, arguments);
|
callback.apply(self, arguments);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
}
|
||||||
return true;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
SteamCommunity.prototype.httpRequestGet = function() {
|
SteamCommunity.prototype.httpRequestGet = function() {
|
||||||
|
Loading…
Reference in New Issue
Block a user