Enable definition of timeouts for xhr-polling

The definition of timeouts is desirable to cancel long outstanding
requests automatically via browser mechanisms. Specifically, it can
happen that lots of pending XHR requests are scheduled, but are never
purged by the browser due to the lack of a timeout definition.
This commit is contained in:
Ben Ripkens
2016-02-24 11:52:01 +01:00
committed by Damien Arrachequesne
parent cea0dffdef
commit 3427e744e1
2 changed files with 9 additions and 2 deletions

View File

@@ -30,6 +30,7 @@ function empty () {}
function XHR (opts) {
Polling.call(this, opts);
this.requestTimeout = opts.requestTimeout;
if (global.location) {
var isSSL = 'https:' === location.protocol;
@@ -84,6 +85,7 @@ XHR.prototype.request = function (opts) {
opts.ca = this.ca;
opts.ciphers = this.ciphers;
opts.rejectUnauthorized = this.rejectUnauthorized;
opts.requestTimeout = this.requestTimeout;
// other options for Node.js client
opts.extraHeaders = this.extraHeaders;
@@ -147,6 +149,7 @@ function Request (opts) {
this.isBinary = opts.isBinary;
this.supportsBinary = opts.supportsBinary;
this.enablesXDR = opts.enablesXDR;
this.requestTimeout = opts.requestTimeout;
// SSL options for Node.js client
this.pfx = opts.pfx;
@@ -228,6 +231,10 @@ Request.prototype.create = function () {
xhr.withCredentials = true;
}
if (this.requestTimeout) {
xhr.timeout = this.requestTimeout;
}
if (this.hasXDR()) {
xhr.onload = function () {
self.onLoad();