OpenLayers OpenLayers

Ticket #410: multiUrls-fix.patch

File multiUrls-fix.patch, 2.7 kB (added by euzuro, 2 years ago)

this fixes the httplayer in opera and ie, and does not break in ff either. the idea is that you cannot safely pass the url variable to Util.getArgs() anymore now that it could be either a string or an array of urls (which, of course, is a perfect example of why making a variable like that which can be of two different types is generally not a good idea). So what we do is we do the deterministic url selecting bit *before* that call... and then we rebuild the paramString again after the call and the check. I have added some basic coments to at least correctly document the type of the 'url' property

  • lib/OpenLayers/Layer/HTTPRequest.js

    old new  
    1212OpenLayers.Layer.HTTPRequest.prototype =  
    1313  OpenLayers.Class.inherit( OpenLayers.Layer, { 
    1414 
    15     /** @type String */ 
     15    /** This is either an array of url strings or a single url string.  
     16     *  
     17     * @type Array(String) or String */ 
    1618    url: null, 
    1719 
    1820    /** Hashtable of key/value parameters 
     21     *  
    1922     * @type Object */ 
    2023    params: null, 
    2124     
     
    3235     * @constructor 
    3336     *  
    3437     * @param {String} name 
    35      * @param {String} url 
     38     * @param {Array(String) or String} url 
    3639     * @param {Object} params 
    3740     * @param {Object} options Hashtable of extra options to tag onto the layer 
    3841     */ 
     
    117120     * @type String 
    118121     */ 
    119122    getFullRequestString:function(newParams, altUrl) { 
     123 
     124        // if not altUrl passed in, use layer's url 
     125        var url = altUrl || this.url; 
    120126         
    121         // use layer's url unless altUrl passed in 
    122         var url = (altUrl == null) ? this.url : altUrl; 
    123          
    124127        // create a new params hashtable with all the layer params and the  
    125128        // new params together. then convert to string 
    126129        var allParams = OpenLayers.Util.extend(new Object(), this.params); 
    127130        allParams = OpenLayers.Util.extend(allParams, newParams); 
     131        var paramsString = OpenLayers.Util.getParameterString(allParams); 
     132         
     133        // if url is not a string, it should be an array of strings,  
     134        // in which case we will deterministically select one of them in  
     135        // order to evenly distribute requests to different urls. 
     136        // 
     137        if (url instanceof Array) { 
     138            url = this.selectUrl(paramsString, url); 
     139        }    
     140  
    128141        // ignore parameters that are already in the url search string 
    129142        var urlParams =  
    130143            OpenLayers.Util.upperCaseObject(OpenLayers.Util.getArgs(url)); 
     
    133146                delete allParams[key]; 
    134147            } 
    135148        } 
    136         var paramsString = OpenLayers.Util.getParameterString(allParams); 
     149        paramsString = OpenLayers.Util.getParameterString(allParams); 
    137150         
    138         // if url is not a string, it should be an array of strings,  
    139         // in which case we will deterministically select one of them in  
    140         // order to evenly distribute requests to different urls. 
    141         if (url instanceof Array) { 
    142             url = this.selectUrl(paramsString, url); 
    143         }    
    144          
    145151        // requestString always starts with url 
    146152        var requestString = url;         
    147153