1 package Catalyst::Engine::Apache;
5 use constant MP2 => $mod_perl::VERSION >= 1.99;
6 use base 'Catalyst::Engine';
9 __PACKAGE__->mk_accessors(qw/apache/);
13 Catalyst::Engine::Apache - Catalyst Apache Engine
21 This is the Catalyst engine specialized for Apache (i.e. for mod_perl).
29 Returns an C<Apache::Request> object.
33 =head1 OVERLOADED METHODS
35 This class overloads some methods from C<Catalyst::Engine>.
39 =item $c->finalize_headers
43 sub finalize_headers {
46 for my $name ( $c->response->headers->header_field_names ) {
47 next if $name =~ /Content-Type/i;
48 my @values = $c->response->header($name);
49 $c->apache->headers_out->add( $name => $_ ) for @values;
52 if ( $c->response->header('Set-Cookie') && $c->response->status >= 300 ) {
53 my @values = $c->response->header('Set-Cookie');
54 $c->apache->err_headers_out->add( 'Set-Cookie' => $_ ) for @values;
57 $c->apache->status( $c->response->status );
58 $c->apache->content_type( $c->response->header('Content-Type') );
61 $c->apache->send_http_header;
67 =item $c->finalize_output
73 $c->apache->print( $c->response->output );
76 =item $c->prepare_connection
80 sub prepare_connection {
82 $c->request->hostname( $c->apache->connection->remote_host );
83 $c->request->address( $c->apache->connection->remote_ip );
86 =item $c->prepare_headers
92 $c->request->method( $c->apache->method );
93 $c->request->header( %{ $c->apache->headers_in } );
96 =item $c->prepare_parameters
100 sub prepare_parameters {
103 foreach my $key ( $c->apache->param ) {
104 my @values = $c->apache->param($key);
105 $args{$key} = @values == 1 ? $values[0] : \@values;
107 $c->request->parameters( \%args );
110 =item $c->prepare_path
114 # XXX needs fixing, only work with <Location> directive,
115 # not <Directory> directive
118 $c->request->path( $c->apache->uri );
119 my $loc = $c->apache->location;
120 no warnings 'uninitialized';
121 $c->req->{path} =~ s/^($loc)?\///;
123 $base->scheme( $ENV{HTTPS} ? 'https' : 'http' );
124 $base->host( $c->apache->hostname );
125 $base->port( $c->apache->get_server_port );
126 my $path = $c->apache->location;
127 $base->path( $path =~ /\/$/ ? $path : "$path/" );
128 $c->request->base( $base->as_string );
131 =item $c->prepare_request($r)
135 sub prepare_request {
137 $c->apache( Apache::Request->new($r) );
140 =item $c->prepare_uploads
144 sub prepare_uploads {
146 for my $upload ( $c->apache->upload ) {
147 $upload = $c->apache->upload($upload) if MP2;
148 $c->request->uploads->{ $upload->filename } = {
150 size => $upload->size,
151 type => $upload->type
170 Sebastian Riedel, C<sri@cpan.org>
174 This program is free software, you can redistribute it and/or modify it under
175 the same terms as Perl itself.