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

Byron Young Byron.Young at riverbed.com
Thu Apr 3 02:12:30 BST 2008


> -----Original Message-----
> From: Dustin Suchter [mailto:dsuchter at ucla.edu]
> Sent: Wednesday, April 02, 2008 5:44 PM
> To: The elegant MVC web framework
> Subject: Re: [Catalyst] Usage of $c->uri_for and $c->res->redirect
>
> So I tried to look at the source of the test that failed, and I'm
> not sure I even understand what it is doing. Here's the actual
> error
> message I'm getting:
>
> t/01use................ok
> t/02pod................skipped: set TEST_POD to enable this test
> t/03podcoverage........skipped: Test::Pod::Coverage 1.04 required
> t/04ssl................1/15
> #   Failed test 'redirect uri ok'
> #   at t/04ssl.t line 43.
> #          got: 'http://localhost:443/ssl/unsecured'
> #     expected: 'http://localhost/ssl/unsecured'
>
> #   Failed test 'redirect with params ok'
> #   at t/04ssl.t line 47.
> #          got:
> 'http://localhost:443/ssl/unsecured?a=1&a=2&b=3&c=4'
> #     expected: 'http://localhost/ssl/unsecured?a=1&a=2&b=3&c=4'
> # Looks like you failed 2 tests of 15.
> t/04ssl................ Dubious, test returned 2 (wstat 512, 0x200)
>   Failed 2/15 subtests
> t/05ssl_host...........ok
> t/06remain_in_ssl......ok
>
> The top error came from:
>
> 40     # test redirect back to http mode
> 41     ok( $res = request('https://localhost/ssl/unsecured'),
> 'request ok' );
> 42     is( $res->code, 302, 'redirect back to http ok' );
> 43     is( $res->header('location'),
> 'http://localhost/ssl/unsecured', 'redirect uri ok' );
>
> So I'm guessing that line #41 is trying to request a secure action
> that would normally redirect you back to an insecure place. This
> jives, because it is requesting an HTTPS URL. However, If I am
> right, then why is it considered a failure to end up on a non-
> secure
> URL? I guess I don't understand what these tests are doing.
>
> -d
>
>
>
>
>
> Those don't make sense to anyone else, either, right? I mean, if
> you
> are going to request a URL from port 443,
>


Heh, you know, I think I force installed that plugin because those test results looked like false negatives.  It has been working fine for me, though.  I probably should have investigated it more, but I just went with it and never looked back.  I'm going to be installing a bunch of the catalyst modules on another server this week, so I'll let you know if I run into the same thing again, and I'll try to look into it if I have time.

Byron


> Dustin Suchter wrote:
> > So I like the idea of the plugin, but I'm having a hard time
> installing
> > it. I found one hit on the Internet that with a report of someone
> else
> > having the exact same problem as me, but I don't see the solution
> online:
> >
> >
> http://www.nntp.perl.org/group/perl.cpan.testers/2007/09/msg631733.
> html
> >
> > Any ideas?
> >
> > Byron Young wrote:
> >>> -----Original Message-----
> >>> From: Dustin Suchter [mailto:dsuchter at ucla.edu]
> >>> Sent: Wednesday, March 26, 2008 1:13 PM
> >>> To: The elegant MVC web framework
> >>> Subject: [Catalyst] Usage of $c->uri_for and $c->res->redirect
> >>>
> >>> 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
> >>
> >> Hey Dustin,
> >>
> >> There's actually a neat plugin for doing this called
> >> Catalyst::Plugin::RequireSSL.  You just include it in your
> plugins and
> >> then call $c->require_ssl() at the top of any actions you want
> to use
> >> SSL for.  It will disable itself automatically on the test
> server, too.
> >>
> >> Cheers,
> >> Byron
> >>
> >> _______________________________________________
> >> 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 at lists.scsys.co.uk/
> Dev site: http://dev.catalyst.perl.org/



More information about the Catalyst mailing list