[Seaside] Issue with #checkForCookies

Julian Fitzell julian at beta4.com
Wed Aug 31 06:52:26 CEST 2005


German,

Sorry I took so long to respond.  I had this message flagged for a reply but 
just came across at again.

I don't see any reason why, in general, you need to redirect while setting a 
cookie unless you want to use the value immediately.

The reason #checkForCookies needs to use it is because it wants to send a 
response to the browser, get another request from the browser confirm that the 
cookie is stored, and then return execution to whatever called it.

I don't see any reason why you couldn't just tack a cookie onto a response 
with #cookieAt:Put: or #addCookie: if you didn't need it until later.  There's 
a space on WARenderingContext for storing the response (and in fact 
WAHtmlRenderer>>response returns it) but it doesn't seem to be set in 
WARenderLoop>>render and nothing seems to use it.

Avi, is there some reason we're not setting the response on the context 
anymore or is it just an omission?.

Julian

Quoting German Viscuso <netquake at speedy.com.ar>:

> Thanks for the tip, I have no previous experience with seaside so I didn't
> know of the class WATask.
> Now I'm checking for cookies from a "go" method in a subclass of WATask but
> the problem persists.
> It seems to be an issue with WASession>>checkForCookies , this method checks
> for cookies by setting a test cookie:
> 
> checkForCookies
>  | check |
>  check := WAExternalID new asString.
>  self redirectWithCookie:
>   (WACookie new
>    key: check;
>    value: 'yes';
>    expireIn: (Duration seconds: 2);
>    yourself).
>  ^ currentRequest cookies includesKey: check
> 
> I do not understand why it is forcing a redirect (which seems to be the
> cause of the warning message). Also, if I try to set a cookie myself via
> #redirectWithCookie: I obtain the same warning message (so the problem may
> be there). As I've read from a previous thread in this list "Cookies
> (again?)" the idea is to force a redirect that sets the cookie and then
> comes right back, but I wonder: is it imperative to set a cookie with a
> redirect?
> 
> Regards and thank you.
> 
> GV
> 
> ----- Original Message ----- 
> From: "Julian Fitzell" <julian at beta4.com>
> To: "The Squeak Enterprise Aubergines Server - general discussion."
> <seaside at lists.squeakfoundation.org>
> Sent: 21 July, 2005 15:25
> Subject: Re: [Seaside] Issue with #checkForCookies
> 
> 
> > Hi German,
> >
> > Well, to be honest I think the cookie stuff was added after I left for
> > Australia so I'm not really familiar with it.  But, what I immediately
> > notice from your code snippet is that you are answering directly from
> > inside a render method, which is a bit unusual.  Since your render
> > method doesn't actually do any rendering, the example you provide below
> > would be much better encapsulated in a subclass of WATask (just put all
> > that code inside the #go method).
> >
> > A task allows you to run through a multistep process, asking questions
> > and defining program flow, whereas a component is really designed to be
> > shown to the user.  It's perfectly acceptable to call #inform: or
> > #answer: inside a callback block that will be triggered by the user and
> > executed during the execution phase.  But once the execution phase has
> > been run and it has been determined that your component should be
> > rendered, you don't want to be calling out to another component.
> >
> > Does that make sense?
> >
> > Julian
> >
> > German Viscuso wrote:
> > > Hello list.
> > >
> > > When I try to use #checkForCookies in a seaside component I obtain the
> > > following
> > > message in the Transcript:
> > >
> > > "Warning: You have tried to set a cookie and a redirect in the same
> page,
> > > responding
> > > to the request /seaside/go/myapp. Some browsers will not handle this
> > > correctly."
> > >
> > > Has this issue been already reported or solved? (I'm using VW 7.3 nc and
> the
> > > web toolkit)
> > >
> > > My test code is:
> >
> > --------------------------------------------------------------------------
> -
> > > renderContentOn: html
> > >
> > > self session checkForCookies
> > >  ifTrue: [
> > >   self inform: 'Cookies enabled!'.
> > >   self answer: 'ok']
> > >  ifFalse: [
> > >   self inform: 'You must have cookies enabled to proceed.'.
> > >   self answer: nil ]
> >
> > --------------------------------------------------------------------------
> -
> > >
> > > Regards and thanks in advance,
> > >
> > > GV
> > >
> > > _______________________________________________
> > > Seaside mailing list
> > > Seaside at lists.squeakfoundation.org
> > > http://lists.squeakfoundation.org/listinfo/seaside
> >
> > -- 
> >    Julian Fitzell  --  Beta4 Productions
> > julian at beta4.com  --  http://www.beta4.com
> > Seaside: http://seaside.st/
> > _______________________________________________
> > Seaside mailing list
> > Seaside at lists.squeakfoundation.org
> > http://lists.squeakfoundation.org/listinfo/seaside
> >
> 
> _______________________________________________
> Seaside mailing list
> Seaside at lists.squeakfoundation.org
> http://lists.squeakfoundation.org/listinfo/seaside
> 


-- 
julian at beta4.com
Beta4 Productions (http://www.beta4.com) 


More information about the Seaside mailing list