Fixed MP2, removed dependency of libapreq in MP engines, fixed C::E::C::APR
[catagits/Catalyst-Runtime.git] / lib / Catalyst / Engine / Apache / Base.pm
CommitLineData
c2e8e6fa 1package Catalyst::Engine::Apache::Base;
2
3use strict;
d837e1a7 4use base qw[Catalyst::Engine Catalyst::Engine::Apache];
c2e8e6fa 5
6use URI;
7use URI::http;
8
9__PACKAGE__->mk_accessors(qw/apache/);
10
11=head1 NAME
12
13Catalyst::Engine::Apache::Base - Base class for Apache Engines
14
15=head1 SYNOPSIS
16
17See L<Catalyst>.
18
19=head1 DESCRIPTION
20
21This is a base class for Apache Engines.
22
23=head1 METHODS
24
25=over 4
26
27=item $c->apache
28
29Returns an C<Apache::Request> object.
30
31=back
32
33=head1 OVERLOADED METHODS
34
35This class overloads some methods from C<Catalyst::Engine>.
36
37=over 4
38
39=item $c->finalize_body
40
41=cut
42
43sub finalize_body {
44 my $c = shift;
45 $c->apache->print( $c->response->body );
46}
47
48=item $c->prepare_body
49
50=cut
51
52sub prepare_body {
53 my $c = shift;
54
55 my $length = $c->request->content_length;
56 my ( $buffer, $content );
57
58 while ($length) {
59
60 $c->apache->read( $buffer, ( $length < 8192 ) ? $length : 8192 );
61
62 $length -= length($buffer);
63 $content .= $buffer;
64 }
65
66 $c->request->body($content);
67}
68
69=item $c->prepare_connection
70
71=cut
72
73sub prepare_connection {
74 my $c = shift;
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 );
78
79 if ( $ENV{HTTPS} || $c->apache->get_server_port == 443 ) {
80 $c->request->secure(1);
81 }
82}
83
84=item $c->prepare_headers
85
86=cut
87
88sub prepare_headers {
89 my $c = shift;
90 $c->request->method( $c->apache->method );
91 $c->request->header( %{ $c->apache->headers_in } );
92}
93
c2e8e6fa 94=item $c->prepare_path
95
96=cut
97
98# XXX needs fixing, only work with <Location> directive,
99# not <Directory> directive
100sub prepare_path {
101 my $c = shift;
102
103 my $base;
104 {
105 my $scheme = $c->request->secure ? 'https' : 'http';
106 my $host = $c->apache->hostname;
107 my $port = $c->apache->get_server_port;
108 my $path = $c->apache->location || '/';
109
110 unless ( $path =~ /\/$/ ) {
111 $path .= '/';
112 }
113
114 $base = URI->new;
115 $base->scheme($scheme);
116 $base->host($host);
117 $base->port($port);
118 $base->path($path);
119
120 $base = $base->canonical->as_string;
121 }
122
123 my $location = $c->apache->location || '/';
124 my $path = $c->apache->uri || '/';
125 $path =~ s/^($location)?\///;
126 $path =~ s/^\///;
127
128 $c->req->base($base);
129 $c->req->path($path);
130}
131
316bf0f0 132=item $c->prepare_request($r)
133
134=cut
135
136sub prepare_request {
137 my ( $c, $r ) = @_;
138 $c->apache($r);
139}
140
c2e8e6fa 141=item $c->run
142
143=cut
144
145sub run { }
146
147=back
148
149=head1 SEE ALSO
150
151L<Catalyst> L<Catalyst::Engine>.
152
153=head1 AUTHOR
154
155Sebastian Riedel, C<sri@cpan.org>
156Christian Hansen C<ch@ngmedia.com>
157
158=head1 COPYRIGHT
159
160This program is free software, you can redistribute it and/or modify it under
161the same terms as Perl itself.
162
163=cut
164
1651;