Replacing Cache-Control header with nonce

Makes long polling work on IE10 and IE9
This commit is contained in:
Pawel Kadluczka 2017-09-11 16:26:10 -07:00 committed by Pawel Kadluczka
parent 67b2b27ac9
commit 54c71c4c10
4 changed files with 60 additions and 48 deletions

View File

@ -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();

View File

@ -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);

View File

@ -4,6 +4,7 @@
"use strict"; "use strict";
describe('connection', function () { describe('connection', function () {
if (typeof WebSocket !== 'undefined') {
it("can connect to the server without specifying transport explicitly", function (done) { it("can connect to the server without specifying transport explicitly", function (done) {
var message = "Hello World!"; var message = "Hello World!";
var connection = new signalR.HttpConnection(ECHOENDPOINT_URL); var connection = new signalR.HttpConnection(ECHOENDPOINT_URL);
@ -28,6 +29,7 @@ describe('connection', function () {
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) {

View File

@ -3,6 +3,7 @@
'use strict'; 'use strict';
if (typeof WebSocket !== 'undefined') {
describe('WebSockets', function () { describe('WebSockets', function () {
it('can be used to connect to SignalR', function (done) { it('can be used to connect to SignalR', function (done) {
var message = "message"; var message = "message";
@ -33,3 +34,4 @@ describe('WebSockets', function () {
}; };
}); });
}); });
}