天高云淡 发表于 2017-2-22 08:39:11

nodejs的cookie实现module(cookie.js)

  文件名:cookie.js
  //Directly send cookie to system, if it's node.js handler, send :
//request.headers.cookie
//If it's socket.io cookie, send :
//client.request.headers.cookie
module.exports.cookie = function(co){
    this.cookies = {};
    co && co.split(';').forEach(function(cookie){
        var parts = cookie.split('=');
        this.cookies.trim()] = (parts || '').trim();
    }.bind(this));

    //Retrieve all cookies available
    this.list = function(){
        return this.cookies;
    };

    //Retrieve a key/value pair
    this.get = function(key){
        if(this.cookies){
            return this.cookies;
        }else{
            return {};
        }
    };

    //Retrieve a list of key/value pair
    this.getList = function(map){
        var cookieRet = {};
        for(var i=0; i<map.length; i++){
            if(this.cookies]){
                cookieRet] = this.cookies];
            }
        }
        return cookieRet;
    };
};
页: [1]
查看完整版本: nodejs的cookie实现module(cookie.js)