[dancer-users] return redirect vs return
Tiago Quintela
kintela at gmail.com
Wed Mar 18 11:33:05 GMT 2015
Hi,
http://search.cpan.org/~yanick/Dancer-1.3134/lib/Dancer.pm#redirect
"Generates an HTTP redirect (302)."
I believe the RFC2616 doesn’t forbid message-body on 300-ish routes so
that’s probably why:
"Redirection is deferred until after the current route or filter has been
processed."
So, if you:
redirect ‘/someroute’ if $something;
return $content;
"means": issue a http 302 to ‘/someroute’ w/ $content as message body.
and,
return redirect '‘/someroute’ if $something
“means": issue a http 302 to ‘/someroute’ and w/o message-body
cheers,
Tiago
On 18 March 2015 at 07:08, Pedro Melo <melo at simplicidade.org> wrote:
> Writing this from memory, but redirect doesn't abort the current request
> processing, so you need to return redirect on all places.
>
> Sent from my iPhone
>
> > On 17/03/2015, at 23:46, David H <untg99 at gmail.com> wrote:
> >
> > So I had this question and I couldn't find any answer, since the two
> options were giving me confusion. I wanted t pass control off to another
> route if a certain action happened.
> >
> > I had this in a route:
> > if ($actionHappened) {
> > redirect '/CheckOffOrderItem/';
> > }
> >
> > and it was working fine, it would pass control off to that route and
> then any return would go to the page and return what I wanted.
> >
> > I then went to add another line for something else below this one
> > if ($theOtherThingHappened) {
> > redirect '/CheckOffProduct/'
> > }
> >
> > and it worked, about twice, then stopped working and wouldn't process
> the redirect, it would get to the condition and go through but just skip
> processing the route and continue with the existing route, so I read
> somewhere that "return redirect" should be used and not "redirect" when
> redirecting.
> >
> > Is this true? and why?
> > My top one is still working and hasn't stopped but I want to know what
> the logic behind these two are. When I changed the second one to 'return
> redirect' it started working again.
> >
> > Thanks,
> >
> > David Hancock
> > _______________________________________________
> > dancer-users mailing list
> > dancer-users at dancer.pm
> > http://lists.preshweb.co.uk/mailman/listinfo/dancer-users
> _______________________________________________
> dancer-users mailing list
> dancer-users at dancer.pm
> http://lists.preshweb.co.uk/mailman/listinfo/dancer-users
>
--
Tiago Quintela
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.preshweb.co.uk/pipermail/dancer-users/attachments/20150318/feb1a52f/attachment.html>
More information about the dancer-users
mailing list