Permalink
Browse files

A couple of mod_perl2 bug fixes.

  • Loading branch information...
1 parent 5fd1cb8 commit c6bc7b37cc6528c4c0d6f6063c830de1281fa97a @theory committed Jul 18, 2006
Showing with 33 additions and 18 deletions.
  1. +3 −0 Changes
  2. +7 −7 lib/Params/Callback.pm
  3. +23 −11 t/08apache.t
View
@@ -1,6 +1,9 @@
Revision history for Perl extension Params::CallbackRequest.
1.16
+ - Fixed bug detecting mod_perl2. Reported by Jimmy Li.
+ - Fixed a bug in the redirect() method under mod_perl2. Report and fix
+ from Jimmy Li.
1.15 2006-05-26T21:28:55
- Added the 'requester' attribute to Params::Callback. This can be
View
@@ -17,12 +17,12 @@ Params::Validate::validation_options
my $is_num = { 'valid priority' => sub { $_[0] =~ /^\d$/ } };
-# Use Apache::RequestRec for mod_perl 2
-my $ap_req_class = defined $mod_perl::VERSION && $mod_perl::VERSION >= 1.99
- ? 'Apache::RequestRec'
- : defined $mod_perl2::VERSION
+# Use Apache2?::RequestRec for mod_perl 2
+use constant APREQ_CLASS => exists $ENV{MOD_PERL_API_VERSION}
+ ? $ENV{MOD_PERL_API_VERSION} >= 2
? 'Apache2::RequestRec'
- : 'Apache';
+ : 'Apache::RequestRec'
+ : 'Apache';
BEGIN {
# The object-oriented interface is only supported with the use of
@@ -59,7 +59,7 @@ my %valid_params = (
},
apache_req => {
- isa => $ap_req_class,
+ isa => APREQ_CLASS,
optional => 1,
},
@@ -354,7 +354,7 @@ sub redirect {
if (my $r = $self->apache_req) {
$r->method('GET');
$r->headers_in->unset('Content-length');
- $r->err_header_out( Location => $url );
+ $r->err_headers_out->add( Location => $url );
}
$self->abort($status) unless $wait;
}
View
@@ -1,6 +1,6 @@
#!perl -w
-# $Id: 08apache.t,v 1.2 2003/08/19 17:39:08 david Exp $
+# $Id$
use strict;
use Test::More;
@@ -10,7 +10,7 @@ my $cbs = [];
BEGIN {
plan skip_all => 'Testing of apache_req requires Apache::FakeRequest'
unless eval { require Apache::FakeRequest };
- plan tests => 14;
+ plan tests => 15;
use_ok('Params::CallbackRequest');
}
@@ -21,6 +21,10 @@ BEGIN {
package Params::Callback::Test::Headers;
sub unset {}
sub new { bless {} }
+sub add {
+ my ($self, $key, $val) = @_;
+ $self->{$key} = $val;
+}
package main;
@@ -51,15 +55,20 @@ push @$cbs, { pkg_key => $key,
##############################################################################
# Create the callback request object.
-ok( my $cb_request = Params::CallbackRequest->new( callbacks => $cbs),
+ok( my $cb_request = Params::CallbackRequest->new( callbacks => $cbs ),
"Construct CBExec object" );
isa_ok($cb_request, 'Params::CallbackRequest' );
# Create an Apache request object.
-ok( my $headers = Params::Callback::Test::Headers->new,
- "Create headers object" );
-
-ok( my $apache_req = Apache::FakeRequest->new( headers_in => $headers ),
+ok( my $headers_in = Params::Callback::Test::Headers->new,
+ "Create headers_in object" );
+ok( my $err_headers_out = Params::Callback::Test::Headers->new,
+ "Create err_headers_out object" );
+
+ok( my $apache_req = Apache::FakeRequest->new(
+ headers_in => $headers_in,
+ err_headers_out => $err_headers_out,
+),
"Create apache request object" );
# Execute the delayed redirection callback.
@@ -68,9 +77,10 @@ my %params = ( "$key|redir_cb" => 1,
is( $cb_request->request(\%params, apache_req => $apache_req), 302,
"Execute delayed redir callback" );
-# Check apache request values (too bad Apache::FakeRequest can't handle
-# parameter lists. This should be good enough, though.
-is( delete $apache_req->{err_header_out}, 'Location', "Check err_header_out" );
+# Check apache request values.
+is_deeply $apache_req->{err_headers_out}, { Location => $url },
+ "Check err_header_out";
+delete $apache_req->{err_headers_out}{Location};
is( delete $apache_req->{method}, 'GET', "Check request method" );
##############################################################################
@@ -80,7 +90,9 @@ is( $cb_request->request(\%params, apache_req => $apache_req), 302,
"Execute instant redir callback" );
# Check the Apache settings again.
-is( delete $apache_req->{err_header_out}, 'Location', "Check err_header_out" );
+is_deeply $apache_req->{err_headers_out}, { Location => $url },
+ "Check err_header_out";
+delete $apache_req->{err_headers_out}{Location};
is( delete $apache_req->{method}, 'GET', "Check request method" );
##############################################################################

0 comments on commit c6bc7b3

Please sign in to comment.