[OpenLayers-Commits] r11093 - in sandbox/elemoine/draw-feature:
lib/OpenLayers lib/OpenLayers/Lang tests
commits-20090109 at openlayers.org
commits-20090109 at openlayers.org
Thu Feb 10 08:43:52 EST 2011
Author: erilem
Date: 2011-02-10 05:43:52 -0800 (Thu, 10 Feb 2011)
New Revision: 11093
Modified:
sandbox/elemoine/draw-feature/lib/OpenLayers/Lang/en.js
sandbox/elemoine/draw-feature/lib/OpenLayers/Lang/fr.js
sandbox/elemoine/draw-feature/lib/OpenLayers/Request.js
sandbox/elemoine/draw-feature/tests/Request.html
Log:
bad merge - changset 11038 wasn't picked up
Modified: sandbox/elemoine/draw-feature/lib/OpenLayers/Lang/en.js
===================================================================
--- sandbox/elemoine/draw-feature/lib/OpenLayers/Lang/en.js 2011-02-10 13:33:20 UTC (rev 11092)
+++ sandbox/elemoine/draw-feature/lib/OpenLayers/Lang/en.js 2011-02-10 13:43:52 UTC (rev 11093)
@@ -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: sandbox/elemoine/draw-feature/lib/OpenLayers/Lang/fr.js
===================================================================
--- sandbox/elemoine/draw-feature/lib/OpenLayers/Lang/fr.js 2011-02-10 13:33:20 UTC (rev 11092)
+++ sandbox/elemoine/draw-feature/lib/OpenLayers/Lang/fr.js 2011-02-10 13:43:52 UTC (rev 11093)
@@ -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: sandbox/elemoine/draw-feature/lib/OpenLayers/Request.js
===================================================================
--- sandbox/elemoine/draw-feature/lib/OpenLayers/Request.js 2011-02-10 13:33:20 UTC (rev 11092)
+++ sandbox/elemoine/draw-feature/lib/OpenLayers/Request.js 2011-02-10 13:43:52 UTC (rev 11093)
@@ -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: sandbox/elemoine/draw-feature/tests/Request.html
===================================================================
--- sandbox/elemoine/draw-feature/tests/Request.html 2011-02-10 13:33:20 UTC (rev 11092)
+++ sandbox/elemoine/draw-feature/tests/Request.html 2011-02-10 13:43:52 UTC (rev 11093)
@@ -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