root / trunk / web / dojo / dojox / io / httpParse.js @ 10
History | View | Annotate | Download (1.34 KB)
| 1 |
/*
|
|---|---|
| 2 |
Copyright (c) 2004-2010, The Dojo Foundation All Rights Reserved.
|
| 3 |
Available via Academic Free License >= 2.1 OR the modified BSD license.
|
| 4 |
see: http://dojotoolkit.org/license for details
|
| 5 |
*/
|
| 6 |
|
| 7 |
|
| 8 |
if(!dojo._hasResource["dojox.io.httpParse"]){ |
| 9 |
dojo._hasResource["dojox.io.httpParse"]=true; |
| 10 |
dojo.provide("dojox.io.httpParse");
|
| 11 |
dojox.io.httpParse=function(_1,_2,_3){ |
| 12 |
var _4=[];
|
| 13 |
var _5=_1.length;
|
| 14 |
do{
|
| 15 |
var _6={};
|
| 16 |
var _7=_1.match(/(\n*[^\n]+)/); |
| 17 |
if(!_7){
|
| 18 |
return null; |
| 19 |
} |
| 20 |
_1=_1.substring(_7[0].length+1); |
| 21 |
_7=_7[1];
|
| 22 |
var _8=_1.match(/([^\n]+\n)*/)[0]; |
| 23 |
_1=_1.substring(_8.length); |
| 24 |
var _9=_1.substring(0,1); |
| 25 |
_1=_1.substring(1);
|
| 26 |
_8=(_2||"")+_8;
|
| 27 |
var _a=_8;
|
| 28 |
_8=_8.match(/[^:\n]+:[^\n]+\n/g);
|
| 29 |
for(var j=0;j<_8.length;j++){ |
| 30 |
var _b=_8[j].indexOf(":"); |
| 31 |
_6[_8[j].substring(0,_b)]=_8[j].substring(_b+1).replace(/(^[ \r\n]*)|([ \r\n]*)$/g,""); |
| 32 |
} |
| 33 |
_7=_7.split(" ");
|
| 34 |
var _c={status:parseInt(_7[1],10),statusText:_7[2],readyState:3,getAllResponseHeaders:function(){ |
| 35 |
return _a;
|
| 36 |
},getResponseHeader:function(_d){ |
| 37 |
return _6[_d];
|
| 38 |
}}; |
| 39 |
var _e=_6["Content-Length"]; |
| 40 |
var _f;
|
| 41 |
if(_e){
|
| 42 |
if(_e<=_1.length){
|
| 43 |
_f=_1.substring(0,_e);
|
| 44 |
}else{
|
| 45 |
return _4;
|
| 46 |
} |
| 47 |
}else{
|
| 48 |
if((_f=_1.match(/(.*)HTTP\/\d\.\d \d\d\d[\w\s]*\n/))){ |
| 49 |
_f=_f[0];
|
| 50 |
}else{
|
| 51 |
if(!_3||_9=="\n"){ |
| 52 |
_f=_1; |
| 53 |
}else{
|
| 54 |
return _4;
|
| 55 |
} |
| 56 |
} |
| 57 |
} |
| 58 |
_4.push(_c); |
| 59 |
_1=_1.substring(_f.length); |
| 60 |
_c.responseText=_f; |
| 61 |
_c.readyState=4;
|
| 62 |
_c._lastIndex=_5-_1.length; |
| 63 |
}while(_1);
|
| 64 |
return _4;
|
| 65 |
}; |
| 66 |
} |