cookies

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
5 messages Options
Reply | Threaded
Open this post in threaded view
|

cookies

Miguel Cobá
Is with a redirect the only way to set a cookie in Seaside?
The WACookieTest class says:

add
        | response |
        self session respond: [ :url |
                response := self session redirectResponseFor: url.
                response addCookie: (WACookie key: key value: value).
                response ].
        key := value := nil

Also the method
self session redirectWithCookie: (WACookie key: #kdy value: var).


Can't I add a cookie to a given response without asking the browser to
make a new request?


--
Miguel Cobá
http://miguel.leugim.com.mx

_______________________________________________
seaside mailing list
[hidden email]
http://lists.squeakfoundation.org/cgi-bin/mailman/listinfo/seaside
Reply | Threaded
Open this post in threaded view
|

Re: cookies

Philippe Marschall
2009/9/22 Miguel Enrique Cobá Martinez <[hidden email]>:

> Is with a redirect the only way to set a cookie in Seaside?
> The WACookieTest class says:
>
> add
>        | response |
>        self session respond: [ :url |
>                response := self session redirectResponseFor: url.
>                response addCookie: (WACookie key: key value: value).
>                response ].
>        key := value := nil
>
> Also the method
> self session redirectWithCookie: (WACookie key: #kdy value: var).
>
>
> Can't I add a cookie to a given response without asking the browser to
> make a new request?

In Seaside 2.8 that's not possible because we don't have access to the
response. In Seaside 3.0 this is possible. If you want/need it in
Seaside 2.8 you'll probably want to add them to your session, add them
to the response in #returnResponse: and then nil them out.

Cheers
Philippe
_______________________________________________
seaside mailing list
[hidden email]
http://lists.squeakfoundation.org/cgi-bin/mailman/listinfo/seaside
Reply | Threaded
Open this post in threaded view
|

Re: cookies

Miguel Cobá
El mar, 22-09-2009 a las 09:41 +0200, Philippe Marschall escribió:

> 2009/9/22 Miguel Enrique Cobá Martinez <[hidden email]>:
> > Is with a redirect the only way to set a cookie in Seaside?
> > The WACookieTest class says:
> >
> > add
> >        | response |
> >        self session respond: [ :url |
> >                response := self session redirectResponseFor: url.
> >                response addCookie: (WACookie key: key value: value).
> >                response ].
> >        key := value := nil
> >
> > Also the method
> > self session redirectWithCookie: (WACookie key: #kdy value: var).
> >
> >
> > Can't I add a cookie to a given response without asking the browser to
> > make a new request?
>
> In Seaside 2.8 that's not possible because we don't have access to the
> response. In Seaside 3.0 this is possible. If you want/need it in
> Seaside 2.8 you'll probably want to add them to your session, add them
> to the response in #returnResponse: and then nil them out.
>
Thank for the answer. I think I will do a redirect until I have no other
option.

> Cheers
> Philippe
> _______________________________________________
> seaside mailing list
> [hidden email]
> http://lists.squeakfoundation.org/cgi-bin/mailman/listinfo/seaside
--
Miguel Cobá
http://miguel.leugim.com.mx

_______________________________________________
seaside mailing list
[hidden email]
http://lists.squeakfoundation.org/cgi-bin/mailman/listinfo/seaside
Reply | Threaded
Open this post in threaded view
|

Re: cookies

Ramon Leon-5

>>> Can't I add a cookie to a given response without asking the browser to
>>> make a new request?
>> In Seaside 2.8 that's not possible because we don't have access to the
>> response. In Seaside 3.0 this is possible. If you want/need it in
>> Seaside 2.8 you'll probably want to add them to your session, add them
>> to the response in #returnResponse: and then nil them out.
>>
> Thank for the answer. I think I will do a redirect until I have no other
> option.

It's fairly trivial to do what you want in 2.8 just by adding a couple
things to your session class.  Something like...

initialize
        super initialize.
        responseBlocks := OrderedCollection new.

onResponse: aBlock
     responseBlocks add: aBlock

returnResponse: aResponse
        responseBlocks do: [:e | e value: aResponse ].
        responseBlocks removeAll.
        ^ super returnResponse: aResponse

Then from your component whenever you want to add something to or do
something with the response, you just do...

self session onResponse: [ :r |
   r addCookie: (WACookie key: #visited value: 'true') ].

Or maybe...

self session onResponse: [ :r | r forbidden ]

--
Ramon Leon
http://onsmalltalk.com
_______________________________________________
seaside mailing list
[hidden email]
http://lists.squeakfoundation.org/cgi-bin/mailman/listinfo/seaside
Reply | Threaded
Open this post in threaded view
|

Re: cookies

Miguel Cobá
El mar, 22-09-2009 a las 09:57 -0700, Ramon Leon escribió:

> >>> Can't I add a cookie to a given response without asking the browser to
> >>> make a new request?
> >> In Seaside 2.8 that's not possible because we don't have access to the
> >> response. In Seaside 3.0 this is possible. If you want/need it in
> >> Seaside 2.8 you'll probably want to add them to your session, add them
> >> to the response in #returnResponse: and then nil them out.
> >>
> > Thank for the answer. I think I will do a redirect until I have no other
> > option.
>
> It's fairly trivial to do what you want in 2.8 just by adding a couple
> things to your session class.  Something like...
>
> initialize
> super initialize.
> responseBlocks := OrderedCollection new.
>
> onResponse: aBlock
>      responseBlocks add: aBlock
>
> returnResponse: aResponse
> responseBlocks do: [:e | e value: aResponse ].
> responseBlocks removeAll.
> ^ super returnResponse: aResponse
>
> Then from your component whenever you want to add something to or do
> something with the response, you just do...
>
> self session onResponse: [ :r |
>    r addCookie: (WACookie key: #visited value: 'true') ].
>
> Or maybe...
>
> self session onResponse: [ :r | r forbidden ]

Cool. Helpful as always.
Thanks
--
Miguel Cobá
http://miguel.leugim.com.mx

_______________________________________________
seaside mailing list
[hidden email]
http://lists.squeakfoundation.org/cgi-bin/mailman/listinfo/seaside