check if using a proxy is required, and if so, issue a warning if none is configured. p=fvanderbiest,me r=me (closes #3015)
git-svn-id: http://svn.openlayers.org/trunk/openlayers@11038 dc9f47b5-9b13-0410-9fdd-eb0c1a62fdaf
This commit is contained in:
@@ -35,6 +35,11 @@ OpenLayers.Request = {
|
||||
scope: null
|
||||
},
|
||||
|
||||
/**
|
||||
* Constant: URL_SPLIT_REGEX
|
||||
*/
|
||||
URL_SPLIT_REGEX: /([^:]*:)\/\/([^:]*:?[^@]*@)?([^:\/\?]*):?([^\/\?]*)/,
|
||||
|
||||
/**
|
||||
* APIProperty: events
|
||||
* {<OpenLayers.Events>} An events object that handles all
|
||||
@@ -128,11 +133,28 @@ OpenLayers.Request = {
|
||||
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(
|
||||
|
||||
Reference in New Issue
Block a user