[Catalyst] Usage of $c->uri_for and $c->res->redirect

KH khultman at gmail.com
Wed Mar 26 20:47:20 GMT 2008


$c->uri_for pulls it's base path from $c->req->base.  Quoting the
documentation in the code:
If your application was queried with the URI
C<http://localhost:3000/some/path> then C<base> is C<http://localhost:3000/
>.

So, setting $c->req->base to your new base would do the trick for you I
think.
You would just do $c->req->base('http://www.mysite.tld:443')

I'm sure they're are other ways to do this too.


On Wed, Mar 26, 2008 at 4:31 PM, Dustin Suchter <dsuchter at ucla.edu> wrote:

> Can you directly control the port you redirect to? Part of my
> problem is having consistency between the production and test
> environments, which operate on 80/443 and 3000/3000 respectively.
>
> -d
>
> Ashley wrote:
> > There are two approaches which have helped me. Remember the URI object
> > underneath can be your friend.
> >
> > 1) Keep things relative.
> >    $c->uri_for("/blah")->path
> >    $c->uri_for("/blah")->path_query
> >
> > 2) Change the scheme yourself.
> >    my $uri =3D $c->uri_for("/blah");
> >    $uri->scheme( $my_test ? "http" : "https" );
> >
> > -Ashley
> >
> > On Mar 26, 2008, at 1:13 PM, Dustin Suchter wrote:
> >
> >> Let's say I want to send people back and forth between an HTTP
> >> connection and an HTTPS connection on a server based on some action.
> >> For example, clicking on a "logout" button from within my application
> >> while connected via HTTPS does something like:
> >>
> >> $c->res->redirect("http://foo.com/");
> >>
> >> The above seems like a fine solution except it totally disregards the
> >> beauty of uri_for, which I would love to be using for stuff like this.
> >> Without uri_for, problems arise when you do things like test via the
> >> built in Perl webserver (the one running on port 3000 by default)
> >> while on the same webserver as my "production" application.
> >>
> >> So the real question is, how do I properly refer to my webserver
> >> and/or application root and include port or SSL flags? I guess I'm
> >> looking for something like $0 within uri_for.
> >>
> >> -d
> >>
> >> _______________________________________________
> >> List: Catalyst at lists.scsys.co.uk
> >> Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst
> >> Searchable archive:
> >> http://www.mail-archive.com/catalyst@lists.scsys.co.uk/
> >> Dev site: http://dev.catalyst.perl.org/
> >
> >
> > _______________________________________________
> > List: Catalyst at lists.scsys.co.uk
> > Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst
> > Searchable archive:
> http://www.mail-archive.com/catalyst@lists.scsys.co.uk/
> > Dev site: http://dev.catalyst.perl.org/
> >
>
> _______________________________________________
> List: Catalyst at lists.scsys.co.uk
> Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst
> Searchable archive:
> http://www.mail-archive.com/catalyst@lists.scsys.co.uk/
> Dev site: http://dev.catalyst.perl.org/
>



-- =

do() || do_not(); // try()
--------------------------------
Catapultam habeo. Nisi pecuniam omnem mihi dabis, ad caput tuum saxum immane
mittam
--------------------------------
http://www.kylehultman.com
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.scsys.co.uk/pipermail/catalyst/attachments/20080326/8514f=
ab9/attachment.htm


More information about the Catalyst mailing list