Replacing Cache-Control header with nonce
Makes long polling work on IE10 and IE9
This commit is contained in:
parent
67b2b27ac9
commit
54c71c4c10
|
|
@ -247,12 +247,12 @@ export class LongPollingTransport implements ITransport {
|
||||||
}
|
}
|
||||||
|
|
||||||
this.pollXhr = pollXhr;
|
this.pollXhr = pollXhr;
|
||||||
this.pollXhr.open("GET", url, true);
|
|
||||||
|
this.pollXhr.open("GET", `${url}&_=${Date.now()}`, true);
|
||||||
if (transferMode === TransferMode.Binary) {
|
if (transferMode === TransferMode.Binary) {
|
||||||
this.pollXhr.responseType = "arraybuffer";
|
this.pollXhr.responseType = "arraybuffer";
|
||||||
}
|
}
|
||||||
// IE caches xhr requests
|
|
||||||
this.pollXhr.setRequestHeader("Cache-Control", "no-cache");
|
|
||||||
// TODO: consider making timeout configurable
|
// TODO: consider making timeout configurable
|
||||||
this.pollXhr.timeout = 120000;
|
this.pollXhr.timeout = 120000;
|
||||||
this.pollXhr.send();
|
this.pollXhr.send();
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,10 @@
|
||||||
var ECHOENDPOINT_URL = "http://" + document.location.host + "/echo";
|
var ECHOENDPOINT_URL = "http://" + document.location.host + "/echo";
|
||||||
|
|
||||||
function getTransportTypes() {
|
function getTransportTypes() {
|
||||||
var transportTypes = [signalR.TransportType.WebSockets];
|
var transportTypes = [];
|
||||||
|
if (typeof WebSocket !== "undefined") {
|
||||||
|
transportTypes.push(signalR.TransportType.WebSockets);
|
||||||
|
}
|
||||||
if (typeof EventSource !== "undefined") {
|
if (typeof EventSource !== "undefined") {
|
||||||
transportTypes.push(signalR.TransportType.ServerSentEvents);
|
transportTypes.push(signalR.TransportType.ServerSentEvents);
|
||||||
}
|
}
|
||||||
|
|
@ -22,7 +25,12 @@ function eachTransport(action) {
|
||||||
}
|
}
|
||||||
|
|
||||||
function eachTransportAndProtocol(action) {
|
function eachTransportAndProtocol(action) {
|
||||||
var protocols = [new signalR.JsonHubProtocol(), new signalRMsgPack.MessagePackHubProtocol()];
|
var protocols = [new signalR.JsonHubProtocol()];
|
||||||
|
// IE9 does not support XmlHttpRequest advanced features so disable for now
|
||||||
|
// This can be enabled if we fix: https://github.com/aspnet/SignalR/issues/742
|
||||||
|
if (typeof new XMLHttpRequest().responseType === "string") {
|
||||||
|
protocols.push(new signalRMsgPack.MessagePackHubProtocol());
|
||||||
|
}
|
||||||
getTransportTypes().forEach(function (t) {
|
getTransportTypes().forEach(function (t) {
|
||||||
return protocols.forEach(function (p) {
|
return protocols.forEach(function (p) {
|
||||||
return action(t, p);
|
return action(t, p);
|
||||||
|
|
|
||||||
|
|
@ -4,30 +4,32 @@
|
||||||
"use strict";
|
"use strict";
|
||||||
|
|
||||||
describe('connection', function () {
|
describe('connection', function () {
|
||||||
it("can connect to the server without specifying transport explicitly", function (done) {
|
if (typeof WebSocket !== 'undefined') {
|
||||||
var message = "Hello World!";
|
it("can connect to the server without specifying transport explicitly", function (done) {
|
||||||
var connection = new signalR.HttpConnection(ECHOENDPOINT_URL);
|
var message = "Hello World!";
|
||||||
|
var connection = new signalR.HttpConnection(ECHOENDPOINT_URL);
|
||||||
|
|
||||||
var received = "";
|
var received = "";
|
||||||
connection.onDataReceived = function (data) {
|
connection.onDataReceived = function (data) {
|
||||||
received += data;
|
received += data;
|
||||||
if (data == message) {
|
if (data == message) {
|
||||||
connection.stop();
|
connection.stop();
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
connection.onClosed = function (error) {
|
connection.onClosed = function (error) {
|
||||||
expect(error).toBeUndefined();
|
expect(error).toBeUndefined();
|
||||||
done();
|
done();
|
||||||
};
|
};
|
||||||
|
|
||||||
connection.start().then(function () {
|
connection.start().then(function () {
|
||||||
connection.send(message);
|
connection.send(message);
|
||||||
}).catch(function (e) {
|
}).catch(function (e) {
|
||||||
fail();
|
fail();
|
||||||
done();
|
done();
|
||||||
|
});
|
||||||
});
|
});
|
||||||
});
|
}
|
||||||
|
|
||||||
eachTransport(function (transportType) {
|
eachTransport(function (transportType) {
|
||||||
it("over " + signalR.TransportType[transportType] + " can send and receive messages", function (done) {
|
it("over " + signalR.TransportType[transportType] + " can send and receive messages", function (done) {
|
||||||
|
|
|
||||||
|
|
@ -3,33 +3,35 @@
|
||||||
|
|
||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
describe('WebSockets', function () {
|
if (typeof WebSocket !== 'undefined') {
|
||||||
it('can be used to connect to SignalR', function (done) {
|
describe('WebSockets', function () {
|
||||||
var message = "message";
|
it('can be used to connect to SignalR', function (done) {
|
||||||
|
var message = "message";
|
||||||
|
|
||||||
var webSocket = new WebSocket(ECHOENDPOINT_URL.replace(/^http/, "ws"));
|
var webSocket = new WebSocket(ECHOENDPOINT_URL.replace(/^http/, "ws"));
|
||||||
|
|
||||||
webSocket.onopen = function () {
|
webSocket.onopen = function () {
|
||||||
webSocket.send(message);
|
webSocket.send(message);
|
||||||
};
|
};
|
||||||
|
|
||||||
var received = "";
|
var received = "";
|
||||||
webSocket.onmessage = function (event) {
|
webSocket.onmessage = function (event) {
|
||||||
received += event.data;
|
received += event.data;
|
||||||
if (received === message) {
|
if (received === message) {
|
||||||
webSocket.close();
|
webSocket.close();
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
webSocket.onclose = function (event) {
|
webSocket.onclose = function (event) {
|
||||||
if (!event.wasClean) {
|
if (!event.wasClean) {
|
||||||
fail("connection closed with unexpected status code: " + event.code + " " + event.reason);
|
fail("connection closed with unexpected status code: " + event.code + " " + event.reason);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Jasmine doesn't like tests without expectations
|
// Jasmine doesn't like tests without expectations
|
||||||
expect(event.wasClean).toBe(true);
|
expect(event.wasClean).toBe(true);
|
||||||
|
|
||||||
done();
|
done();
|
||||||
};
|
};
|
||||||
|
});
|
||||||
});
|
});
|
||||||
});
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue