Although I'm not sure, but I guess, that the exception is the reason
for this effect.
I think, but I'm not entirely sure that, within camping/session the
code in the service method after its super is not called, when the
exeption is raised. This code is the one, that sets the cookie
information.
This is the code in camping/session.rb
def service(*a)
session = Camping::Models::Session.persist @cookies
app = self.class.name.gsub(/^(\w+)::.+$/, '\1')
@state = (session[app] ||= Camping::H[])
hash_before = Marshal.dump(@state).hash
s = super(*a)
if session
hash_after = Marshal.dump(@state).hash
unless hash_before == hash_after
session[app] = @state
session.save
end
end
s
end
The exception is raised in the super(*a) line, this transfer the
control flow to your rescue line and it never comes back.
The only possibility would be to avoid exceptions to manipulate your
control flow.
Cheers,
Gregor
On 9/25/07, Julian 'Julik' Tarkhanov <[EMAIL PROTECTED]> wrote:
>
> Hello Campers!
>
> Is it just me or does Camping init the session twice on a redirect? If I
> have an app and when the user visits it for the first time, a session is
> generated. Afterwards I redirect the user in a service (that basically does
> auth) and he gets bounced to the login page - but when I arrive at the login
> page my SID somehow has changed :-( so there is a stale session dangling in
> the store and and empty @state.
> After the second request (even if I fail auth or load a page that does not
> require it beforehand) everything is fine and dandy.
>
> Herre is the service in question - if I do it like this the session is
> regenerated when the user lands on the signon page And the page he is
> redirected from was his first one
> in the session
>
> def service(*a)
> begin
> return super(*a)
> rescue PleaseLogin
> redirect R(Pasaporte::Controllers::Signon,
> @nickname)
> return self
> end
> self
> end
>
> And this version works in all cases:
>
>
> def service(*a)
> begin
> return super(*a)
> rescue PleaseLogin
> @headers['Set-Cookie'] = 'camping_sid=%s; path=/' %
> @cookies.camping_sid
> redirect R(Pasaporte::Controllers::Signon,
> @nickname)
> return self
> end
> self
> end
>
> Of course the service is included before Camping::Session so the session
> service should wrap.
> Has someone observed this behavior? Why is it needed to manually set the
> session cookie? Is it that the same as the workaround that mod_perl and
> mod_python use (as in "error headers" versus "normal headers")?
>
> --
> Julian 'Julik' Tarkhanov
> please send all personal mail to [EMAIL PROTECTED]
>
>
>
>
> _______________________________________________
> Camping-list mailing list
> [email protected]
> http://rubyforge.org/mailman/listinfo/camping-list
>
_______________________________________________
Camping-list mailing list
[email protected]
http://rubyforge.org/mailman/listinfo/camping-list