Cookies - in Jack or Nitro

3 views
Skip to first unread message

Roberto Saccon

unread,
Mar 8, 2010, 1:25:37 PM3/8/10
to nitro-devel
I need Cookies, and took a look at nitro/cookie.js, which offers:


var Cookie = exports.Cookie = function(key, value) { ...}

/**
* Set the cookie into the Response headers.
*/
Cookie.prototype.setHeader = function(headers) {

but Jack also has:
=============

Response.prototype.setCookie = function(key, value) { ... }

Response.prototype.deleteCookie // unimplemented


Which implementation should be used to set the cookies ? And how do we
read cookies ? I was looking for a method like: getCookie(key). Is
that missing or is there a better way to do that ?

--
Roberto

George Moschovitis

unread,
Mar 8, 2010, 4:38:27 PM3/8/10
to nitro...@googlegroups.com
Have a look at

lib/jack/session/cookie.js 

for answers.

in short:

var request = new Request(env),
     cookies = request.cookies(),
     cookie = cookies[key];

response.setCookie(key, value).

I think the Cookie.setHeader or something similar is more useful (no need to create a Response object).
Will have to research this and/or discuss with Tom.

-g.


--
You received this message because you are subscribed to the Google Groups "nitro-devel" group.
To post to this group, send email to nitro...@googlegroups.com.
To unsubscribe from this group, send email to nitro-devel...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/nitro-devel?hl=en.




--
http://www.gmosx.com/blog

George Moschovitis

unread,
Mar 8, 2010, 4:44:06 PM3/8/10
to nitro...@googlegroups.com
Nah, I think this should do the trick:

var Request = require("jack/response"), 
     Response = require("jack/response");

exports.GET = function (env) {
    var request = new Request(env),
          cookies = request.cookies();

    var auth = cookies["auth"];

    ...

    var response = new Response();
    response.setCookie("mykey", "myvalue");
    return response;
}


Perhaps we should add a request.getCookie() helper method.

-g.

Roberto Saccon

unread,
Mar 8, 2010, 4:59:14 PM3/8/10
to nitro-devel
ah, great, now I see that everything needed is actually there
already !

thanks a lot
--
Roberto

On Mar 8, 6:44 pm, George Moschovitis <george-moschovi...@gmosx.com>
wrote:

> > On Mon, Mar 8, 2010 at 8:25 PM, Roberto Saccon <rsac...@gmail.com> wrote:
>
> >> I need Cookies, and took a look at nitro/cookie.js, which offers:
>
> >>  var Cookie = exports.Cookie = function(key, value) { ...}
>
> >>  /**
> >>   * Set the cookie into the Response headers.
> >>   */
> >>  Cookie.prototype.setHeader = function(headers) {
>
> >> but Jack also has:
> >> =============
>
> >>  Response.prototype.setCookie = function(key, value) { ... }
>
> >>  Response.prototype.deleteCookie // unimplemented
>
> >> Which implementation should be used to set the cookies ? And how do we
> >> read cookies ? I was looking for a method  like: getCookie(key). Is
> >> that missing or is there a better way to do that ?
>
> >> --
> >> Roberto
>
> >> --
> >> You received this message because you are subscribed to the Google Groups
> >> "nitro-devel" group.
> >> To post to this group, send email to nitro...@googlegroups.com.
> >> To unsubscribe from this group, send email to

> >> nitro-devel...@googlegroups.com<nitro-devel%2Bunsubscribe@googlegr oups.com>

Reply all
Reply to author
Forward
0 new messages