mirror of
https://github.com/socketio/socket.io.git
synced 2026-04-30 03:00:39 -04:00
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:
committed by
Damien Arrachequesne
parent
cea0dffdef
commit
3427e744e1
@@ -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();
|
||||
|
||||
Reference in New Issue
Block a user