Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

Already on GitHub? Sign in to your account

Lazy cookies #1139

Closed
tj opened this Issue May 15, 2012 · 7 comments

Comments

Projects
None yet
5 participants
Owner

tj commented May 15, 2012

we should be able to do this in a backwards compatible-ish way, req.cookies.get(name) vs req.cookies.name, for now we could use getters to unsign / parse json cookies. Getters are lame but at least then we dont have to wait until 4.x for this. The original res.cookie(name, value[, options]) API would remain, however req.cookies.set(name, value[, options]) would compliment the .get() method using jed's cookie lib(s)

I was thinking .. to mount a function. req.cookie(name) so bring the value of the cookie.

something like

req.cookie = function( name ){
    var nameEQ = name + '=',
        rawcok = this.header('cookie'),
        ca = rawcok ? rawcok.split(';') : [""];
    for ( var i = 0; i < ca.length; i++) {
        var c = ca[i];
        while (c.charAt(0) == ' ')
            c = c.substring(1, c.length);
        if (c.indexOf(nameEQ) == 0)
            return c.substring(nameEQ.length, c.length);
    }
    return null;
};

in the file express/lib/request.js in the line 328

Contributor

buschtoens commented May 30, 2012

@visionmedia Uhm... Isn't this Connect's task? Since when does Express support cookies by default? Or are you planning to implement them?

Owner

tj commented May 30, 2012

the res.cookie() method is Express, req.cookies is cookieParser(). The lazy change would end up in connect but the issue queue is a bit of a mess haha.. wish I had time to go through and clean them up

Contributor

defunctzombie commented May 30, 2012

What is the advantage of the lazy cookie? Is the parsing overhead a concern currently?

Owner

tj commented May 30, 2012

performance-wise it would be nicer if you're not actually utilizing the cookie but yeah until we bench the current stuff who cares really. the signed cookie parsing could be improved as-is, we could prefix something like s: to indicate that it's signed instead of the optimistic parsing that we have right now

I just realized that just changed the utlidad express.cookieParser() can not be called directly. To generate a Json

@jonathanong jonathanong referenced this issue Nov 30, 2013

Closed

Express 4.0 #1838

8 of 11 tasks complete

@jonathanong jonathanong was assigned Dec 4, 2013

@jonathanong jonathanong referenced this issue in expressjs/session Feb 16, 2014

Open

cookies and keygrip #1

Contributor

defunctzombie commented Feb 22, 2014

Closing this since it doesn't seem to be high priority or "broken" for anyone. Haven't seen many issues that complain about this nor does it prevent someone from using their own middleware to do whatever things they want.

@jonathanong jonathanong was unassigned by tj Jul 29, 2014

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment