On Fri, Nov 13, 2009 at 6:46 AM, Jeppe Nejsum Madsen <je...@ingolfs.dk>wrote:
> > David Pollak <feeder.of.the.be...@gmail.com> writes: > > [...] > > > Yes. The rewrite phase takes place very early in the HTTP > request/response > > cycle. It takes place before the statelessDispatch call. The > > statelessDispatch call is very important for REST style APIs as it does > > *not* cause the creation of a session, thus for lots of API calls, we > don't > > have a session created for each call. > > > > The rewrite phase has to come before the statelessDispatch phase because > the > > request has to be properly rewritten before being pattern matched against > > the partial functions that define the statelessDispatch > > > > Based on some of your prior needs, I've made the session available during > > the rewrite phase, but it's only if the session actually exists > (basically, > > the request is checked for a session, but the request is not told "create > > one if it doesn't already exists". > > I sort of guessed it had to do with this. I find rewriting really useful > to write apps that need to extract info from the URL in a type-safe way > before continuing the processing. > > I seem to run into a number of issues with this approach (some which > you've fixed, thanks!), so was wondering if perhaps I'm misusing > rewriting and there are better ways to approach this? > > A few thoughts: > > - Is it possible to create a session manually in the rewrite phase? Yes. Please open a ticket > If > no, maybe a LiftRule PF that could be used to force session creation > for certain requests? > No, because we don't know what the request is during the rewrite phase. > > - Would it be possible to detect (at least in Dev mode) some of these > misuses (i.e. using a SessionVar with no session) and emit a warning? > Yes. Please open a ticket. > > > So, the first request from a browser does not have a session and thus > does > > not have session vars. Is there a way you can use RequestVars here? > > I guess I can hack something together for this case, but I need to think > a little more to make sure it fits cleanly with the rest. > Generally, the rewrite phase should not have side effects. Yeah, storing something in a RequestVar is one thing, but changing session state is another. I would strongly suggest looking at your code and seeing if you can set the SessionVar in the business logic portion of your code. > > If I just redirect back to the same page, will this trigger the session > creation or does the redirect happen before the session is created? > You could manually force the session to be created and then redirect. > > It's a multipage workflow, so SessionVars seem like the easy way out > :-) > Wizard is coming. :-) > > /Jeppe > > > > > -- Lift, the simply functional web framework http://liftweb.net Beginning Scala http://www.apress.com/book/view/1430219890 Follow me: http://twitter.com/dpp Surf the harmonics --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Lift" group. To post to this group, send email to liftweb@googlegroups.com To unsubscribe from this group, send email to liftweb+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/liftweb?hl=en -~----------~----~----~----~------~----~------~--~---