allow proxy host function, r=tschaub (closes #2128)
git-svn-id: http://svn.openlayers.org/trunk/openlayers@9586 dc9f47b5-9b13-0410-9fdd-eb0c1a62fdaf
This commit is contained in:
@@ -128,7 +128,11 @@ OpenLayers.Request = {
|
||||
}
|
||||
}
|
||||
if(config.proxy && (url.indexOf("http") == 0)) {
|
||||
url = config.proxy + encodeURIComponent(url);
|
||||
if(typeof config.proxy == "function") {
|
||||
url = config.proxy(url);
|
||||
} else {
|
||||
url = config.proxy + encodeURIComponent(url);
|
||||
}
|
||||
}
|
||||
request.open(
|
||||
config.method, url, config.async, config.user, config.password
|
||||
|
||||
@@ -318,6 +318,59 @@
|
||||
|
||||
}
|
||||
|
||||
function test_ProxyHost(t) {
|
||||
t.plan(4);
|
||||
|
||||
/*
|
||||
* Setup
|
||||
*/
|
||||
|
||||
setup();
|
||||
|
||||
var expectedURL;
|
||||
|
||||
var _ProxyHost = OpenLayers.ProxyHost;
|
||||
|
||||
var proto = OpenLayers.Request.XMLHttpRequest.prototype;
|
||||
var _open = proto.open;
|
||||
var log = [];
|
||||
proto.open = function(method, url, async, user, password) {
|
||||
log.push(url);
|
||||
};
|
||||
|
||||
/*
|
||||
* Test
|
||||
*/
|
||||
|
||||
// 2 tests
|
||||
log = [];
|
||||
OpenLayers.ProxyHost = "http://fooproxy/?url=";
|
||||
expectedURL = "http://fooproxy/?url=http%3A%2F%2Fbar%3Fk1%3Dv1%26k2%3Dv2";
|
||||
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] + ")");
|
||||
|
||||
// 2 tests
|
||||
log = []
|
||||
OpenLayers.ProxyHost = function(url) {
|
||||
var p = OpenLayers.Util.getParameters(url);
|
||||
var p = OpenLayers.Util.getParameterString(p);
|
||||
return "http://barproxy/?" + p;
|
||||
};
|
||||
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] + ")");
|
||||
|
||||
/*
|
||||
* Teardown
|
||||
*/
|
||||
|
||||
OpenLayers.Request.XMLHttpRequest.prototype.open = _open;
|
||||
OpenLayers.ProxyHost = _ProxyHost;
|
||||
teardown();
|
||||
}
|
||||
|
||||
</script>
|
||||
</head>
|
||||
<body>
|
||||
|
||||
Reference in New Issue
Block a user