GUAC-1083: Add CORS support to Guacamole.HTTPTunnel

This commit is contained in:
david
2015-02-11 11:03:00 +02:00
committed by Michael Jumper
parent c3b6d68588
commit 8d4e413e2c

View File

@@ -138,8 +138,9 @@ Guacamole.Tunnel.State = {
* @constructor * @constructor
* @augments Guacamole.Tunnel * @augments Guacamole.Tunnel
* @param {String} tunnelURL The URL of the HTTP tunneling service. * @param {String} tunnelURL The URL of the HTTP tunneling service.
* @param {Boolean} withCredentials HTTP requests 'withCredentials' header value.
*/ */
Guacamole.HTTPTunnel = function(tunnelURL) { Guacamole.HTTPTunnel = function(tunnelURL, withCredentials) {
/** /**
* Reference to this HTTP tunnel. * Reference to this HTTP tunnel.
@@ -162,6 +163,8 @@ Guacamole.HTTPTunnel = function(tunnelURL) {
var sendingMessages = false; var sendingMessages = false;
var outputMessageBuffer = ""; var outputMessageBuffer = "";
withCredentials = !!withCredentials;
/** /**
* The current receive timeout ID, if any. * The current receive timeout ID, if any.
* @private * @private
@@ -278,6 +281,7 @@ Guacamole.HTTPTunnel = function(tunnelURL) {
var message_xmlhttprequest = new XMLHttpRequest(); var message_xmlhttprequest = new XMLHttpRequest();
message_xmlhttprequest.open("POST", TUNNEL_WRITE + tunnel_uuid); message_xmlhttprequest.open("POST", TUNNEL_WRITE + tunnel_uuid);
message_xmlhttprequest.withCredentials = withCredentials;
message_xmlhttprequest.setRequestHeader("Content-type", "application/x-www-form-urlencoded; charset=UTF-8"); message_xmlhttprequest.setRequestHeader("Content-type", "application/x-www-form-urlencoded; charset=UTF-8");
// Once response received, send next queued event. // Once response received, send next queued event.
@@ -508,6 +512,7 @@ Guacamole.HTTPTunnel = function(tunnelURL) {
// Make request, increment request ID // Make request, increment request ID
var xmlhttprequest = new XMLHttpRequest(); var xmlhttprequest = new XMLHttpRequest();
xmlhttprequest.open("GET", TUNNEL_READ + tunnel_uuid + ":" + (request_id++)); xmlhttprequest.open("GET", TUNNEL_READ + tunnel_uuid + ":" + (request_id++));
xmlhttprequest.withCredentials = withCredentials;
xmlhttprequest.send(null); xmlhttprequest.send(null);
return xmlhttprequest; return xmlhttprequest;
@@ -547,6 +552,7 @@ Guacamole.HTTPTunnel = function(tunnelURL) {
}; };
connect_xmlhttprequest.open("POST", TUNNEL_CONNECT, true); connect_xmlhttprequest.open("POST", TUNNEL_CONNECT, true);
connect_xmlhttprequest.withCredentials = withCredentials;
connect_xmlhttprequest.setRequestHeader("Content-type", "application/x-www-form-urlencoded; charset=UTF-8"); connect_xmlhttprequest.setRequestHeader("Content-type", "application/x-www-form-urlencoded; charset=UTF-8");
connect_xmlhttprequest.send(data); connect_xmlhttprequest.send(data);