From ac949589a0773f60f57a9a54c76d2f25c9f68d34 Mon Sep 17 00:00:00 2001 From: euzuro Date: Thu, 16 Nov 2006 09:03:17 +0000 Subject: [PATCH] applying patch for #399 - MultiServer - some small formatting/commenting changes. git-svn-id: http://svn.openlayers.org/trunk/openlayers@1872 dc9f47b5-9b13-0410-9fdd-eb0c1a62fdaf --- examples/multiserver.html | 35 +++++++++++++++++++++++++++++ lib/OpenLayers/Layer/HTTPRequest.js | 11 ++++++--- 2 files changed, 43 insertions(+), 3 deletions(-) create mode 100644 examples/multiserver.html diff --git a/examples/multiserver.html b/examples/multiserver.html new file mode 100644 index 0000000000..37609c54b2 --- /dev/null +++ b/examples/multiserver.html @@ -0,0 +1,35 @@ + + + + + + + +
+ + diff --git a/lib/OpenLayers/Layer/HTTPRequest.js b/lib/OpenLayers/Layer/HTTPRequest.js index 5953983cce..53f68126b5 100644 --- a/lib/OpenLayers/Layer/HTTPRequest.js +++ b/lib/OpenLayers/Layer/HTTPRequest.js @@ -109,6 +109,12 @@ OpenLayers.Layer.HTTPRequest.prototype = // use layer's url unless altUrl passed in var url = (altUrl == null) ? this.url : altUrl; + // if url is not a string, it should be an array of strings, + // in which case we will randomly select one of them in order + // to evenly distribute requests to different urls. + if (typeof url == "object") { + url = url[Math.floor(Math.random()*url.length)]; + } // requestString always starts with url var requestString = url; @@ -117,13 +123,12 @@ OpenLayers.Layer.HTTPRequest.prototype = var allParams = OpenLayers.Util.extend(new Object(), this.params); var allParams = OpenLayers.Util.extend(allParams, newParams); var paramsString = OpenLayers.Util.getParameterString(allParams); - if (paramsString != "") { - var lastServerChar = this.url.charAt(this.url.length - 1); + var lastServerChar = url.charAt(url.length - 1); if ((lastServerChar == "&") || (lastServerChar == "?")) { requestString += paramsString; } else { - if (this.url.indexOf('?') == -1) { + if (url.indexOf('?') == -1) { //serverPath has no ? -- add one requestString += '?' + paramsString; } else {