[Catalyst] Re: Redirects // Re: forwarding to chained actions

2007-04-27 Thread A. Pagaltzis
* Simon Wilcox [EMAIL PROTECTED] [2007-04-27 15:10]:
 So, what do people do - do you send 303/307's correctly or
 just default to 302 behaviour?

I send 303, unless the HTTP request uses HTTP 1.0, in which case
the client sees a 302 instead.

Regards,
-- 
Aristotle Pagaltzis // http://plasmasturm.org/

___
List: Catalyst@lists.rawmode.org
Listinfo: http://lists.rawmode.org/mailman/listinfo/catalyst
Searchable archive: http://www.mail-archive.com/catalyst@lists.rawmode.org/
Dev site: http://dev.catalyst.perl.org/


[Catalyst] Re: Redirects // Re: forwarding to chained actions

2007-04-27 Thread A. Pagaltzis
* Bill Moseley [EMAIL PROTECTED] [2007-04-27 20:55]:
 sub post_redirect {
 my ( $c, $location ) = @_;
 my ($version) = $c-request-protocol =~ m/(\d+\.\d+)/;
 
 # Make location absolute
 $location = $c-uri_for( $location )
 unless $location =~ /http/;
 
 $c-res-redirect( $location, ( $version  $version  1.0 ? 303 : 302 ));
 }

Various nitpickery corrected:

sub post_redirect {
my ( $c, $loc ) = @_;

my $is_rel_uri = $loc !~ m{ :// }x;

my $is_old_proto = do {
my $p = $c-request-protocol;
my ( $maj, $min ) = ( $p =~ m{ \A HTTP / 0* ( \d+ ) \. ( \d+ ) \z 
}x );
not $maj or $maj == 1 and $min == 0;
};

$c-res-redirect(
( $is_rel_uri   ? $c-uri_for( $loc ) : $loc ),
( $is_old_proto ? 302 : 303 ),
);
}

Main change is because HTTP versions are not floats. (Someone
tell me, when doesn’t comparing version strings properly suck?)

-- 
*AUTOLOAD=*_;sub _{s/(.*)::(.*)/print$2,(,$\/, )[defined wantarray]/e;$1}
Just-another-Perl-hack;
#Aristotle

___
List: Catalyst@lists.rawmode.org
Listinfo: http://lists.rawmode.org/mailman/listinfo/catalyst
Searchable archive: http://www.mail-archive.com/catalyst@lists.rawmode.org/
Dev site: http://dev.catalyst.perl.org/


Re: [Catalyst] Re: Redirects // Re: forwarding to chained actions

2007-04-27 Thread Bill Moseley
On Fri, Apr 27, 2007 at 10:30:01PM +0200, A. Pagaltzis wrote:
 Various nitpickery corrected:
 
 sub post_redirect {
 my ( $c, $loc ) = @_;
 
 my $is_rel_uri = $loc !~ m{ :// }x;
 
 my $is_old_proto = do {
 my $p = $c-request-protocol;
 my ( $maj, $min ) = ( $p =~ m{ \A HTTP / 0* ( \d+ ) \. ( \d+ ) \z 
 }x );
 not $maj or $maj == 1 and $min == 0;
 };
 
 $c-res-redirect(
 ( $is_rel_uri   ? $c-uri_for( $loc ) : $loc ),
 ( $is_old_proto ? 302 : 303 ),
 );
 }

I was going to say Quick! Make a plugin on CPAN but then realized
the above exceeds the line limit for Catalyst plugins. ;)

-- 
Bill Moseley
[EMAIL PROTECTED]


___
List: Catalyst@lists.rawmode.org
Listinfo: http://lists.rawmode.org/mailman/listinfo/catalyst
Searchable archive: http://www.mail-archive.com/catalyst@lists.rawmode.org/
Dev site: http://dev.catalyst.perl.org/