1 package Catalyst::Engine::Apache;
5 use constant MP2 => $mod_perl::VERSION >= 1.99;
6 use base 'Catalyst::Engine';
10 __PACKAGE__->mk_accessors(qw/apache/);
14 Catalyst::Engine::Apache - Catalyst Apache Engine
22 This is the Catalyst engine specialized for Apache (i.e. for mod_perl).
30 Returns an C<Apache::Request> object.
34 =head1 OVERLOADED METHODS
36 This class overloads some methods from C<Catalyst::Engine>.
40 =item $c->finalize_headers
44 sub finalize_headers {
47 for my $name ( $c->response->headers->header_field_names ) {
48 next if $name =~ /Content-Type/i;
49 my @values = $c->response->header($name);
50 $c->apache->headers_out->add( $name => $_ ) for @values;
53 if ( $c->response->header('Set-Cookie') && $c->response->status >= 300 ) {
54 my @values = $c->response->header('Set-Cookie');
55 $c->apache->err_headers_out->add( 'Set-Cookie' => $_ ) for @values;
58 $c->apache->status( $c->response->status );
59 $c->apache->content_type( $c->response->header('Content-Type') );
62 $c->apache->send_http_header;
68 =item $c->finalize_output
74 $c->apache->print( $c->response->output );
77 =item $c->prepare_connection
81 sub prepare_connection {
83 $c->request->hostname( $c->apache->connection->remote_host );
84 $c->request->address( $c->apache->connection->remote_ip );
87 =item $c->prepare_headers
93 $c->request->method( $c->apache->method );
94 $c->request->header( %{ $c->apache->headers_in } );
97 =item $c->prepare_parameters
101 sub prepare_parameters {
104 foreach my $key ( $c->apache->param ) {
105 my @values = $c->apache->param($key);
106 $args{$key} = @values == 1 ? $values[0] : \@values;
108 $c->request->parameters( \%args );
111 =item $c->prepare_path
115 # XXX needs fixing, only work with <Location> directive,
116 # not <Directory> directive
119 $c->request->path( $c->apache->uri );
120 my $loc = $c->apache->location;
121 no warnings 'uninitialized';
122 $c->req->{path} =~ s/^($loc)?\///;
124 $base->scheme( $ENV{HTTPS} ? 'https' : 'http' );
125 $base->host( $c->apache->hostname );
126 $base->port( $c->apache->get_server_port );
127 my $path = $c->apache->location;
128 $base->path( $path =~ /\/$/ ? $path : "$path/" );
129 $c->request->base( $base->as_string );
132 =item $c->prepare_request($r)
136 sub prepare_request {
138 $c->apache( Apache::Request->new($r) );
141 =item $c->prepare_uploads
145 sub prepare_uploads {
147 for my $upload ( $c->apache->upload ) {
148 $upload = $c->apache->upload($upload) if MP2;
149 $c->request->uploads->{ $upload->filename } = {
151 size => $upload->size,
152 type => $upload->type
171 Sebastian Riedel, C<sri@cpan.org>
175 This program is free software, you can redistribute it and/or modify it under
176 the same terms as Perl itself.