Entries

笔记:用于ServerXMLHttp的Cookie容器 / CookieContainer For ServerXMLHTTP

可能有BUG,还没全面测试过。
This might be buggy.
(function(){
var rxTrim = /^\s+|\s+$/g
String.prototype.trim = function trim(){
return this.replace(rxTrim, "");
}
})();

function CookieContainer(){
}
(function(){
var cc = CookieContainer;

var $def = { "": 0, expires: 0, domain: 0, path: 0 };
cc.prototype.push = function push(lines){
var ls = lines.split("\r\n");
for(var i = 0; i < ls.length; i++){
var l = ls[i];
if(l.substr(0, 11).toLowerCase() == "set-cookie:"){
var vs = l.substr(11).split(";"), sc = {}, path;

for(var ii = 0; ii < vs.length; ii++){
var sl = vs[ii].trim();
if(sl.substr(0, 5) == "path="){
path = sl.substr(5);
continue;
}
var sk = sl.substr(0, sl.indexOf("="));
if(sk in $def){
continue;
}
sc[sk] = decodeURIComponent(sl.substr(sk.length + 1));
}

for(var k in sc){
if(sc.propertyIsEnumerable(k)){
this.set(k, sc[k], path);
}
}
}
}
};
cc.prototype.set = function set(n, v, p){
p = cc.fix(p);
var o = (this[p] || (this[p] ={}));
o[n] = v;
};
cc.prototype.del = function del(n, p){
p = cc.fix(p);
delete this[p][n];
};
cc.prototype.get = function get(p){
p = cc.fix(p);
var o = {}, sc, a = [];

while(p.length > 0){
if(sc = this[p]){
for(var i in sc){
if(!(i in o)){
o[i] = sc[i];
}
}
}

p = (p.length > 1) ? p.substr(0, p.lastIndexOf("/", p.length - 2) + 1) : "";
}

for(var i in o){
o.propertyIsEnumerable(i) && a.push(i + "=" + encodeURIComponent(o[i]));
}
return a.join("; ");
};
cc.fix = function fix(p){
return p ? ((p.charAt(p.length - 1) == "/") ? p : (p + "/")) : "/";
};
})();
引用此文章(FC2博客用户)
http://shinron4.blog126.fc2blog.us/tb.php/41-a50c5f71

引用

留言

发表留言

发表留言
只对管理员显示

Appendix

自我介绍

优雅的神棍 / Elegant Tales

Author:优雅的神棍 / Elegant Tales
神棍你好,神棍再见。

最新引用

QR

QR

羔羊们啊

加为好友

和此人成爲好友

搜寻栏