GUACAMOLE-437: Fix extraHeaders in the StaticHTTPTunnel

Project: http://git-wip-us.apache.org/repos/asf/incubator-guacamole-client/repo
Commit: 
http://git-wip-us.apache.org/repos/asf/incubator-guacamole-client/commit/e12d5479
Tree: 
http://git-wip-us.apache.org/repos/asf/incubator-guacamole-client/tree/e12d5479
Diff: 
http://git-wip-us.apache.org/repos/asf/incubator-guacamole-client/diff/e12d5479

Branch: refs/heads/master
Commit: e12d5479732472d11c244b5b218160312b01533a
Parents: 227e41f
Author: Ignasi Barrera <n...@apache.org>
Authored: Mon Nov 20 18:43:14 2017 +0100
Committer: Ignasi Barrera <n...@apache.org>
Committed: Mon Nov 20 18:43:14 2017 +0100

----------------------------------------------------------------------
 .../src/main/webapp/modules/Tunnel.js           | 35 ++++++++++++++++++--
 1 file changed, 33 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-guacamole-client/blob/e12d5479/guacamole-common-js/src/main/webapp/modules/Tunnel.js
----------------------------------------------------------------------
diff --git a/guacamole-common-js/src/main/webapp/modules/Tunnel.js 
b/guacamole-common-js/src/main/webapp/modules/Tunnel.js
index a36c144..c8f8502 100644
--- a/guacamole-common-js/src/main/webapp/modules/Tunnel.js
+++ b/guacamole-common-js/src/main/webapp/modules/Tunnel.js
@@ -1091,8 +1091,13 @@ Guacamole.ChainedTunnel.prototype = new 
Guacamole.Tunnel();
  *     Whether tunnel requests will be cross-domain, and thus must use CORS
  *     mechanisms and headers. By default, it is assumed that tunnel requests
  *     will be made to the same domain.
+ *
+ * @param {Object} [extraTunnelHeaders={}]
+ *     Key value pairs containing the header names and values of any additional
+ *     headers to be sent in tunnel requests. By default, no extra headers will
+ *     be added.
  */
-Guacamole.StaticHTTPTunnel = function StaticHTTPTunnel(url, crossDomain) {
+Guacamole.StaticHTTPTunnel = function StaticHTTPTunnel(url, crossDomain, 
extraTunnelHeaders) {
 
     /**
      * Reference to this Guacamole.StaticHTTPTunnel.
@@ -1111,6 +1116,32 @@ Guacamole.StaticHTTPTunnel = function 
StaticHTTPTunnel(url, crossDomain) {
     var xhr = null;
 
     /**
+     * Additional headers to be sent in tunnel requests. This dictionary can be
+     * populated with key/value header pairs to pass information such as 
authentication
+     * tokens, etc.
+     *
+     * @private
+     */
+    var extraHeaders = extraTunnelHeaders || {};
+
+    /**
+     * Adds the configured additional headers to the given request.
+     *
+     * @param {XMLHttpRequest} request
+     *     The request where the configured extra headers will be added.
+     *
+     * @param {Object} headers
+     *     The headers to be added to the request.
+     *
+     * @private
+     */
+    function addExtraHeaders(request, headers) {
+        for (var name in headers) {
+            request.setRequestHeader(name, headers[name]);
+        }
+    }
+
+    /**
      * Returns the Guacamole protocol status code which most closely
      * represents the given HTTP status code.
      *
@@ -1171,7 +1202,7 @@ Guacamole.StaticHTTPTunnel = function 
StaticHTTPTunnel(url, crossDomain) {
         xhr = new XMLHttpRequest();
         xhr.open('GET', url);
         xhr.withCredentials = !!crossDomain;
-        addExtraHeaders(xhr);
+        addExtraHeaders(xhr, extraHeaders);
         xhr.responseType = 'text';
         xhr.send(null);
 

Reply via email to