Ticket #27: JsonRpc-UseProperMimeAndPerformanceImprovement.patch

File JsonRpc-UseProperMimeAndPerformanceImprovement.patch, 4.6 kB (added by heldermagalhaes, 7 months ago)

fixes issue and add up a performance boost by removing unneeded whitespace

  • jsonrpc.js

    old new  
    7373        @param trace=undefined  The error causing this Exception 
    7474    **/ 
    7575    publ __init__(msg, err, trace){ 
    76         supr.__init__.call(this, msg, trace); 
     76        supr.__init__.call(this, msg, trace); 
    7777        this.error = err; 
    7878    }; 
    7979}); 
     
    9696        var v=[]; 
    9797        for(var attr in obj){ 
    9898            if(typeof obj[attr] != "function"){ 
    99                 v.push(marshall(attr) + ': ' + marshall(obj[attr])); 
     99                    /* 
     100                     * Fix by Helder Magalhães (HMM), 2007-07-27 
     101                     *  
     102                     * Removed whitespace to improve performance and save bandwidth 
     103                     */ 
     104                    v.push('"' + attr + '":' + mod.marshall(obj[attr])); 
    100105            } 
    101106        } 
     107            /* 
     108             * Fix by Helder Magalhães (HMM), 2007-07-27 
     109             *  
     110             * Removed whitespace to improve performance and save bandwidth 
     111             */ 
    102112        return "{" + v.join(", ") + "}"; 
    103113    } 
    104114}; 
     
    132142     
    133143    var postData = function(url, user, pass, data, callback){ 
    134144        if(callback == null){//todo ===undefined 
    135             var rslt = urllib.postURL(url, user, pass, data, [["Content-Type", "text/plain"]]); 
     145                /* 
     146                 * Fix by Helder Magalhães (HMM), 2007-07-27 
     147                 *  
     148                 * Changed MIME type to "application/json" 
     149                 * (http://www.apps.ietf.org/rfc/rfc4627.html#sec-6) 
     150                 * (http://json-rpc.org/wd/JSON-RPC-1-1-WD-20060807.html#RequestHeaders) 
     151                 */ 
     152                var rslt = urllib.postURL(url, user, pass, data, [["Content-Type", "application/json"]]); 
    136153            return rslt; 
    137154        }else{ 
    138             return urllib.postURL(url, user, pass, data, [["Content-Type", "text/plain"]], callback); 
     155                return urllib.postURL(url, user, pass, data, [["Content-Type", "application/json"]], callback); 
    139156        } 
    140157    }; 
    141158 
     
    167184    }; 
    168185 
    169186    var jsonRequest = function(id, methodName, args){ 
    170         var p = [marshall(id), marshall(methodName), marshall(args)]; 
     187            var p = [mod.marshall(id), mod.marshall(methodName), mod.marshall(args)]; 
     188            /* 
     189             * Fix by Helder Magalhães (HMM), 2007-07-27 
     190             *  
     191             * Removed whitespace to improve performance and save bandwidth 
     192             */ 
    171193        return '{"id":' + p[0] + ', "method":' + p[1] + ', "params":' + p[2] + "}"; 
    172194    }; 
    173195    /** 
     
    185207    }; 
    186208 
    187209    publ __call__(){ 
    188         var args=new Array(); 
    189          
    190         for(var i=0;i<this._defaultArgs.length;i++){ 
    191             args.push(this._defaultArgs[i]); 
    192         } 
     210        var args=new Array(); 
    193211         
     212        for(var i=0;i<this._defaultArgs.length;i++){ 
     213            args.push(this._defaultArgs[i]); 
     214        } 
     215         
    194216        for(var i=0;i<arguments.length;i++){ 
    195217            args.push(arguments[i]); 
    196218        } 
    197219        //sync or async call 
    198220        if(typeof arguments[arguments.length-1] !='function'){ 
    199             var data=jsonRequest("httpReq", this.methodName, args); 
     221                /* 
     222                 * Fix by Helder Magalhães (HMM), 2007-07-27 
     223                 *  
     224                 * Changed "httpReq" to a shorter string to improve performance and save bandwidth 
     225                 */ 
     226                var data=jsonRequest("HR", this.methodName, args); 
    200227            var resp = postData(this.url, this.user, this.password, data); 
    201228            return handleResponse(resp); 
    202229        }else{ 
    203230            var cb = args.pop(); //get rid of the function argument 
    204             var data=jsonRequest("httpReq", this.methodName, args); 
     231                var data=jsonRequest("HR", this.methodName, args); 
    205232            return postData(this.url, this.user, this.password, data, function(resp){ 
    206233                var rslt = null; 
    207234                var exc =null; 
     
    249276    ///The user name used for HTTP authorization. 
    250277    publ user; 
    251278    ///The password used for HTTP authorization. 
    252     publ password; 
    253      
     279    publ password; 
     280     
    254281    publ _defaultArgs=[]; 
    255282}); 
    256283 
     
    562589    for(var i=0;i<this.length;i++){ 
    563590        v.push(marshall(this[i])) ; 
    564591    } 
     592        /* 
     593         * Fix by Helder Magalhães (HMM), 2007-07-27 
     594         *  
     595         * Removed whitespace to improve performance and save bandwidth 
     596         */ 
    565597    return "[" + v.join(", ") + "]"; 
    566598}; 
    567599