[OpenLayers-Commits] r11038 - in trunk/openlayers: lib/OpenLayers lib/OpenLayers/Lang tests

commits-20090109 at openlayers.org commits-20090109 at openlayers.org
Mon Jan 17 19:13:35 EST 2011


Author: ahocevar
Date: 2011-01-17 16:13:35 -0800 (Mon, 17 Jan 2011)
New Revision: 11038

Modified:
   trunk/openlayers/lib/OpenLayers/Lang/en.js
   trunk/openlayers/lib/OpenLayers/Lang/fr.js
   trunk/openlayers/lib/OpenLayers/Request.js
   trunk/openlayers/tests/Request.html
Log:
check if using a proxy is required, and if so, issue a warning if none is configured. p=fvanderbiest,me r=me (closes #3015)


Modified: trunk/openlayers/lib/OpenLayers/Lang/en.js
===================================================================
--- trunk/openlayers/lib/OpenLayers/Lang/en.js	2011-01-17 14:39:27 UTC (rev 11037)
+++ trunk/openlayers/lib/OpenLayers/Lang/en.js	2011-01-18 00:13:35 UTC (rev 11038)
@@ -122,6 +122,9 @@
     // console message
     'filterEvaluateNotImplemented': "evaluate is not implemented for this filter type.",
 
+    'proxyNeeded': "You probably need to set OpenLayers.ProxyHost to access ${url}."+
+        "See http://trac.osgeo.org/openlayers/wiki/FrequentlyAskedQuestions#ProxyHost",
+
     // **** end ****
     'end': ''
     

Modified: trunk/openlayers/lib/OpenLayers/Lang/fr.js
===================================================================
--- trunk/openlayers/lib/OpenLayers/Lang/fr.js	2011-01-17 14:39:27 UTC (rev 11037)
+++ trunk/openlayers/lib/OpenLayers/Lang/fr.js	2011-01-18 00:13:35 UTC (rev 11038)
@@ -75,6 +75,7 @@
 
     'pagePositionFailed': "OpenLayers.Util.pagePosition a échoué: l\'élément d\'id ${elemId} pourrait être mal positionné.",
 
-    'filterEvaluateNotImplemented': "évaluer n\'a pas encore été implémenté pour ce type de filtre."
+    'filterEvaluateNotImplemented': "évaluer n\'a pas encore été implémenté pour ce type de filtre.",
 
+    'proxyNeeded': "Vous avez très probablement besoin de renseigner OpenLayers.ProxyHost pour accéder à ${url}. Voir http://trac.osgeo.org/openlayers/wiki/FrequentlyAskedQuestions#ProxyHost"
 });

Modified: trunk/openlayers/lib/OpenLayers/Request.js
===================================================================
--- trunk/openlayers/lib/OpenLayers/Request.js	2011-01-17 14:39:27 UTC (rev 11037)
+++ trunk/openlayers/lib/OpenLayers/Request.js	2011-01-18 00:13:35 UTC (rev 11038)
@@ -36,6 +36,11 @@
     },
     
     /**
+     * Constant: URL_SPLIT_REGEX
+     */
+    URL_SPLIT_REGEX: /([^:]*:)\/\/([^:]*:?[^@]*@)?([^:\/\?]*):?([^\/\?]*)/,
+    
+    /**
      * APIProperty: events
      * {<OpenLayers.Events>} An events object that handles all 
      *     events on the {<OpenLayers.Request>} object.
@@ -128,11 +133,28 @@
                 url += separator + paramString;
             }
         }
-        if(config.proxy && (url.indexOf("http") == 0)) {
-            if(typeof config.proxy == "function") {
-                url = config.proxy(url);
+        var sameOrigin = !(url.indexOf("http") == 0);
+        var urlParts = !sameOrigin && url.match(this.URL_SPLIT_REGEX);
+        if (urlParts) {
+            var location = window.location;
+            sameOrigin =
+                urlParts[1] == location.protocol &&
+                urlParts[3] == location.hostname;
+            var uPort = urlParts[4], lPort = location.port;
+            if (uPort != 80 && uPort != "" || lPort != "80" && lPort != "") {
+                sameOrigin = sameOrigin && uPort == lPort;
+            }
+        }
+        if (!sameOrigin) {
+            if (config.proxy) {
+                if (typeof config.proxy == "function") {
+                    url = config.proxy(url);
+                } else {
+                    url = config.proxy + encodeURIComponent(url);
+                }
             } else {
-                url = config.proxy + encodeURIComponent(url);
+                OpenLayers.Console.warn(
+                    OpenLayers.i18n("proxyNeeded"), {url: url});
             }
         }
         request.open(

Modified: trunk/openlayers/tests/Request.html
===================================================================
--- trunk/openlayers/tests/Request.html	2011-01-17 14:39:27 UTC (rev 11037)
+++ trunk/openlayers/tests/Request.html	2011-01-18 00:13:35 UTC (rev 11038)
@@ -319,7 +319,7 @@
     }
 
     function test_ProxyHost(t) {
-        t.plan(4);
+        t.plan(5);
 
         /*
          * Setup
@@ -334,6 +334,7 @@
         var proto = OpenLayers.Request.XMLHttpRequest.prototype;
         var _open = proto.open;
         var log = [];
+        var port;
         proto.open = function(method, url, async, user, password) {
             log.push(url);
         };
@@ -349,9 +350,17 @@
         OpenLayers.Request.GET({url: "http://bar?k1=v1&k2=v2"});
         t.eq(log.length, 1, "[1] XHR.open called once");
         t.eq(log[0], expectedURL, "[1] the URL used for XHR is correct (" + log[0] + ")");
-
+        
+        // 1 test
+        log = [];
+        OpenLayers.ProxyHost = "http://fooproxy/?url=";
+        port = window.location.port ? ':'+window.location.port : '';
+        expectedURL = window.location.protocol+"//"+window.location.hostname+port+"/service";
+        OpenLayers.Request.GET({url: expectedURL});
+        t.eq(log[0], expectedURL, "[2] proxy is not used when requesting the same server");
+        
         // 2 tests
-        log = []
+        log = [];
         OpenLayers.ProxyHost = function(url) {
             var p = OpenLayers.Util.getParameters(url);
             var p = OpenLayers.Util.getParameterString(p);
@@ -359,8 +368,8 @@
         };
         expectedURL = "http://barproxy/?k1=v1&k2=v2";
         OpenLayers.Request.GET({url: "http://bar?k1=v1&k2=v2"});
-        t.eq(log.length, 1, "[2] XHR.open called once");
-        t.eq(log[0], expectedURL, "[2] the URL used for XHR is correct (" + log[0] + ")");
+        t.eq(log.length, 1, "[3] XHR.open called once");
+        t.eq(log[0], expectedURL, "[3] the URL used for XHR is correct (" + log[0] + ")");
 
         /*
          * Teardown



More information about the Commits mailing list