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.open("GET", url, true);
|
||||
|
||||
this.pollXhr.open("GET", `${url}&_=${Date.now()}`, true);
|
||||
if (transferMode === TransferMode.Binary) {
|
||||
this.pollXhr.responseType = "arraybuffer";
|
||||
}
|
||||
// IE caches xhr requests
|
||||
this.pollXhr.setRequestHeader("Cache-Control", "no-cache");
|
||||
|
||||
// TODO: consider making timeout configurable
|
||||
this.pollXhr.timeout = 120000;
|
||||
this.pollXhr.send();
|
||||
|
|
|
|||
|
|
@ -6,7 +6,10 @@
|
|||
var ECHOENDPOINT_URL = "http://" + document.location.host + "/echo";
|
||||
|
||||
function getTransportTypes() {
|
||||
var transportTypes = [signalR.TransportType.WebSockets];
|
||||
var transportTypes = [];
|
||||
if (typeof WebSocket !== "undefined") {
|
||||
transportTypes.push(signalR.TransportType.WebSockets);
|
||||
}
|
||||
if (typeof EventSource !== "undefined") {
|
||||
transportTypes.push(signalR.TransportType.ServerSentEvents);
|
||||
}
|
||||
|
|
@ -22,7 +25,12 @@ function eachTransport(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) {
|
||||
return protocols.forEach(function (p) {
|
||||
return action(t, p);
|
||||
|
|
|
|||
|
|
@ -4,30 +4,32 @@
|
|||
"use strict";
|
||||
|
||||
describe('connection', function () {
|
||||
it("can connect to the server without specifying transport explicitly", function (done) {
|
||||
var message = "Hello World!";
|
||||
var connection = new signalR.HttpConnection(ECHOENDPOINT_URL);
|
||||
if (typeof WebSocket !== 'undefined') {
|
||||
it("can connect to the server without specifying transport explicitly", function (done) {
|
||||
var message = "Hello World!";
|
||||
var connection = new signalR.HttpConnection(ECHOENDPOINT_URL);
|
||||
|
||||
var received = "";
|
||||
connection.onDataReceived = function (data) {
|
||||
received += data;
|
||||
if (data == message) {
|
||||
connection.stop();
|
||||
}
|
||||
};
|
||||
var received = "";
|
||||
connection.onDataReceived = function (data) {
|
||||
received += data;
|
||||
if (data == message) {
|
||||
connection.stop();
|
||||
}
|
||||
};
|
||||
|
||||
connection.onClosed = function (error) {
|
||||
expect(error).toBeUndefined();
|
||||
done();
|
||||
};
|
||||
connection.onClosed = function (error) {
|
||||
expect(error).toBeUndefined();
|
||||
done();
|
||||
};
|
||||
|
||||
connection.start().then(function () {
|
||||
connection.send(message);
|
||||
}).catch(function (e) {
|
||||
fail();
|
||||
done();
|
||||
connection.start().then(function () {
|
||||
connection.send(message);
|
||||
}).catch(function (e) {
|
||||
fail();
|
||||
done();
|
||||
});
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
eachTransport(function (transportType) {
|
||||
it("over " + signalR.TransportType[transportType] + " can send and receive messages", function (done) {
|
||||
|
|
|
|||
|
|
@ -3,33 +3,35 @@
|
|||
|
||||
'use strict';
|
||||
|
||||
describe('WebSockets', function () {
|
||||
it('can be used to connect to SignalR', function (done) {
|
||||
var message = "message";
|
||||
if (typeof WebSocket !== 'undefined') {
|
||||
describe('WebSockets', function () {
|
||||
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.send(message);
|
||||
};
|
||||
webSocket.onopen = function () {
|
||||
webSocket.send(message);
|
||||
};
|
||||
|
||||
var received = "";
|
||||
webSocket.onmessage = function (event) {
|
||||
received += event.data;
|
||||
if (received === message) {
|
||||
webSocket.close();
|
||||
}
|
||||
};
|
||||
var received = "";
|
||||
webSocket.onmessage = function (event) {
|
||||
received += event.data;
|
||||
if (received === message) {
|
||||
webSocket.close();
|
||||
}
|
||||
};
|
||||
|
||||
webSocket.onclose = function (event) {
|
||||
if (!event.wasClean) {
|
||||
fail("connection closed with unexpected status code: " + event.code + " " + event.reason);
|
||||
}
|
||||
webSocket.onclose = function (event) {
|
||||
if (!event.wasClean) {
|
||||
fail("connection closed with unexpected status code: " + event.code + " " + event.reason);
|
||||
}
|
||||
|
||||
// Jasmine doesn't like tests without expectations
|
||||
expect(event.wasClean).toBe(true);
|
||||
// Jasmine doesn't like tests without expectations
|
||||
expect(event.wasClean).toBe(true);
|
||||
|
||||
done();
|
||||
};
|
||||
done();
|
||||
};
|
||||
});
|
||||
});
|
||||
});
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue