Ticket #27: JsonRpc-UseProperMimeAndPerformanceImprovement.patch
| File JsonRpc-UseProperMimeAndPerformanceImprovement.patch, 4.6 kB (added by heldermagalhaes, 7 months ago) |
|---|
-
jsonrpc.js
old new 73 73 @param trace=undefined The error causing this Exception 74 74 **/ 75 75 publ __init__(msg, err, trace){ 76 supr.__init__.call(this, msg, trace); 76 supr.__init__.call(this, msg, trace); 77 77 this.error = err; 78 78 }; 79 79 }); … … 96 96 var v=[]; 97 97 for(var attr in obj){ 98 98 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])); 100 105 } 101 106 } 107 /* 108 * Fix by Helder Magalhães (HMM), 2007-07-27 109 * 110 * Removed whitespace to improve performance and save bandwidth 111 */ 102 112 return "{" + v.join(", ") + "}"; 103 113 } 104 114 }; … … 132 142 133 143 var postData = function(url, user, pass, data, callback){ 134 144 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"]]); 136 153 return rslt; 137 154 }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); 139 156 } 140 157 }; 141 158 … … 167 184 }; 168 185 169 186 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 */ 171 193 return '{"id":' + p[0] + ', "method":' + p[1] + ', "params":' + p[2] + "}"; 172 194 }; 173 195 /** … … 185 207 }; 186 208 187 209 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(); 193 211 212 for(var i=0;i<this._defaultArgs.length;i++){ 213 args.push(this._defaultArgs[i]); 214 } 215 194 216 for(var i=0;i<arguments.length;i++){ 195 217 args.push(arguments[i]); 196 218 } 197 219 //sync or async call 198 220 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); 200 227 var resp = postData(this.url, this.user, this.password, data); 201 228 return handleResponse(resp); 202 229 }else{ 203 230 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); 205 232 return postData(this.url, this.user, this.password, data, function(resp){ 206 233 var rslt = null; 207 234 var exc =null; … … 249 276 ///The user name used for HTTP authorization. 250 277 publ user; 251 278 ///The password used for HTTP authorization. 252 publ password; 253 279 publ password; 280 254 281 publ _defaultArgs=[]; 255 282 }); 256 283 … … 562 589 for(var i=0;i<this.length;i++){ 563 590 v.push(marshall(this[i])) ; 564 591 } 592 /* 593 * Fix by Helder Magalhães (HMM), 2007-07-27 594 * 595 * Removed whitespace to improve performance and save bandwidth 596 */ 565 597 return "[" + v.join(", ") + "]"; 566 598 }; 567 599
