1 package Catalyst::Engine::Apache;
4 use base 'Catalyst::Engine';
9 __PACKAGE__->mk_accessors(qw/apache/);
13 Catalyst::Engine::Apache - Catalyst Apache Engine
21 This is a base class 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_body
45 $c->apache->print( $c->response->body );
48 =item $c->prepare_body
55 my $length = $c->request->content_length;
56 my ( $buffer, $content );
60 $c->apache->read( $buffer, ( $length < 8192 ) ? $length : 8192 );
62 $length -= length($buffer);
66 $c->request->body($content);
69 =item $c->prepare_connection
73 sub prepare_connection {
75 $c->request->address( $c->apache->connection->remote_ip );
76 $c->request->hostname( $c->apache->connection->remote_host );
77 $c->request->protocol( $c->apache->protocol );
79 if ( $ENV{HTTPS} || $c->apache->get_server_port == 443 ) {
80 $c->request->secure(1);
84 =item $c->prepare_headers
90 $c->request->method( $c->apache->method );
91 $c->request->header( %{ $c->apache->headers_in } );
94 =item $c->prepare_parameters
98 sub prepare_parameters {
103 $c->apache->param->do( sub {
104 my ( $field, $value ) = @_;
105 push( @params, $field, $value );
109 $c->request->param(@params);
112 =item $c->prepare_path
116 # XXX needs fixing, only work with <Location> directive,
117 # not <Directory> directive
123 my $scheme = $c->request->secure ? 'https' : 'http';
124 my $host = $c->apache->hostname;
125 my $port = $c->apache->get_server_port;
126 my $path = $c->apache->location || '/';
128 unless ( $path =~ /\/$/ ) {
133 $base->scheme($scheme);
138 $base = $base->canonical->as_string;
141 my $location = $c->apache->location || '/';
142 my $path = $c->apache->uri || '/';
143 $path =~ s/^($location)?\///;
146 $c->req->base($base);
147 $c->req->path($path);
164 Sebastian Riedel, C<sri@cpan.org>
165 Christian Hansen C<ch@ngmedia.com>
169 This program is free software, you can redistribute it and/or modify it under
170 the same terms as Perl itself.