Skip to content

Commit

Permalink
A couple of mod_perl2 bug fixes.
Browse files Browse the repository at this point in the history
  • Loading branch information
theory committed Jul 18, 2006
1 parent 5fd1cb8 commit c6bc7b3
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 18 deletions.
3 changes: 3 additions & 0 deletions Changes
@@ -1,6 +1,9 @@
Revision history for Perl extension Params::CallbackRequest. Revision history for Perl extension Params::CallbackRequest.


1.16 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 1.15 2006-05-26T21:28:55
- Added the 'requester' attribute to Params::Callback. This can be - Added the 'requester' attribute to Params::Callback. This can be
Expand Down
14 changes: 7 additions & 7 deletions lib/Params/Callback.pm
Expand Up @@ -17,12 +17,12 @@ Params::Validate::validation_options


my $is_num = { 'valid priority' => sub { $_[0] =~ /^\d$/ } }; my $is_num = { 'valid priority' => sub { $_[0] =~ /^\d$/ } };


# Use Apache::RequestRec for mod_perl 2 # Use Apache2?::RequestRec for mod_perl 2
my $ap_req_class = defined $mod_perl::VERSION && $mod_perl::VERSION >= 1.99 use constant APREQ_CLASS => exists $ENV{MOD_PERL_API_VERSION}
? 'Apache::RequestRec' ? $ENV{MOD_PERL_API_VERSION} >= 2
: defined $mod_perl2::VERSION
? 'Apache2::RequestRec' ? 'Apache2::RequestRec'
: 'Apache'; : 'Apache::RequestRec'
: 'Apache';


BEGIN { BEGIN {
# The object-oriented interface is only supported with the use of # The object-oriented interface is only supported with the use of
Expand Down Expand Up @@ -59,7 +59,7 @@ my %valid_params = (
}, },


apache_req => { apache_req => {
isa => $ap_req_class, isa => APREQ_CLASS,
optional => 1, optional => 1,
}, },


Expand Down Expand Up @@ -354,7 +354,7 @@ sub redirect {
if (my $r = $self->apache_req) { if (my $r = $self->apache_req) {
$r->method('GET'); $r->method('GET');
$r->headers_in->unset('Content-length'); $r->headers_in->unset('Content-length');
$r->err_header_out( Location => $url ); $r->err_headers_out->add( Location => $url );
} }
$self->abort($status) unless $wait; $self->abort($status) unless $wait;
} }
Expand Down
34 changes: 23 additions & 11 deletions t/08apache.t
@@ -1,6 +1,6 @@
#!perl -w #!perl -w


# $Id: 08apache.t,v 1.2 2003/08/19 17:39:08 david Exp $ # $Id$


use strict; use strict;
use Test::More; use Test::More;
Expand All @@ -10,7 +10,7 @@ my $cbs = [];
BEGIN { BEGIN {
plan skip_all => 'Testing of apache_req requires Apache::FakeRequest' plan skip_all => 'Testing of apache_req requires Apache::FakeRequest'
unless eval { require Apache::FakeRequest }; unless eval { require Apache::FakeRequest };
plan tests => 14; plan tests => 15;
use_ok('Params::CallbackRequest'); use_ok('Params::CallbackRequest');
} }


Expand All @@ -21,6 +21,10 @@ BEGIN {
package Params::Callback::Test::Headers; package Params::Callback::Test::Headers;
sub unset {} sub unset {}
sub new { bless {} } sub new { bless {} }
sub add {
my ($self, $key, $val) = @_;
$self->{$key} = $val;
}


package main; package main;


Expand Down Expand Up @@ -51,15 +55,20 @@ push @$cbs, { pkg_key => $key,


############################################################################## ##############################################################################
# Create the callback request object. # 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" ); "Construct CBExec object" );
isa_ok($cb_request, 'Params::CallbackRequest' ); isa_ok($cb_request, 'Params::CallbackRequest' );


# Create an Apache request object. # Create an Apache request object.
ok( my $headers = Params::Callback::Test::Headers->new, ok( my $headers_in = Params::Callback::Test::Headers->new,
"Create headers object" ); "Create headers_in object" );

ok( my $err_headers_out = Params::Callback::Test::Headers->new,
ok( my $apache_req = Apache::FakeRequest->new( headers_in => $headers ), "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" ); "Create apache request object" );


# Execute the delayed redirection callback. # Execute the delayed redirection callback.
Expand All @@ -68,9 +77,10 @@ my %params = ( "$key|redir_cb" => 1,
is( $cb_request->request(\%params, apache_req => $apache_req), 302, is( $cb_request->request(\%params, apache_req => $apache_req), 302,
"Execute delayed redir callback" ); "Execute delayed redir callback" );


# Check apache request values (too bad Apache::FakeRequest can't handle # Check apache request values.
# parameter lists. This should be good enough, though. is_deeply $apache_req->{err_headers_out}, { Location => $url },
is( delete $apache_req->{err_header_out}, 'Location', "Check err_header_out" ); "Check err_header_out";
delete $apache_req->{err_headers_out}{Location};
is( delete $apache_req->{method}, 'GET', "Check request method" ); is( delete $apache_req->{method}, 'GET', "Check request method" );


############################################################################## ##############################################################################
Expand All @@ -80,7 +90,9 @@ is( $cb_request->request(\%params, apache_req => $apache_req), 302,
"Execute instant redir callback" ); "Execute instant redir callback" );


# Check the Apache settings again. # 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" ); is( delete $apache_req->{method}, 'GET', "Check request method" );


############################################################################## ##############################################################################
Expand Down

0 comments on commit c6bc7b3

Please sign in to comment.