Added $c-req->protocol and $c->req->secure
[catagits/Catalyst-Runtime.git] / lib / Catalyst / Engine / Apache.pm
CommitLineData
fc7ec1d9 1package Catalyst::Engine::Apache;
2
3use strict;
fc7ec1d9 4use base 'Catalyst::Engine';
e7c0c583 5
fc7ec1d9 6use URI;
bc146cf4 7use URI::http;
fc7ec1d9 8
6dc87a0f 9__PACKAGE__->mk_accessors(qw/apache/);
fc7ec1d9 10
11=head1 NAME
12
13Catalyst::Engine::Apache - Catalyst Apache Engine
14
15=head1 SYNOPSIS
16
17See L<Catalyst>.
18
19=head1 DESCRIPTION
20
329a7e51 21This is a base class engine specialized for Apache (i.e. for mod_perl).
fc7ec1d9 22
23f9d934 23=head1 METHODS
fc7ec1d9 24
23f9d934 25=over 4
26
6dc87a0f 27=item $c->apache
fc7ec1d9 28
29Returns an C<Apache::Request> object.
30
23f9d934 31=back
32
33=head1 OVERLOADED METHODS
fc7ec1d9 34
35This class overloads some methods from C<Catalyst::Engine>.
36
23f9d934 37=over 4
38
06e1b616 39=item $c->finalize_body
fc7ec1d9 40
41=cut
42
06e1b616 43sub finalize_body {
fc7ec1d9 44 my $c = shift;
e060fe05 45 $c->apache->print( $c->response->body );
fc7ec1d9 46}
47
06e1b616 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
e060fe05 66 $c->request->body($content);
06e1b616 67}
68
0556eb49 69=item $c->prepare_connection
70
71=cut
72
73sub prepare_connection {
74 my $c = shift;
6dc87a0f 75 $c->request->address( $c->apache->connection->remote_ip );
bfde09a2 76 $c->request->hostname( $c->apache->connection->remote_host );
77 $c->request->protocol( $c->apache->protocol );
78
79 if ( $ENV{HTTPS} ) {
80 $c->request->secure(1);
81 }
fc7ec1d9 82}
83
23f9d934 84=item $c->prepare_headers
fc7ec1d9 85
86=cut
87
88sub prepare_headers {
89 my $c = shift;
6dc87a0f 90 $c->request->method( $c->apache->method );
91 $c->request->header( %{ $c->apache->headers_in } );
fc7ec1d9 92}
93
23f9d934 94=item $c->prepare_parameters
fc7ec1d9 95
96=cut
97
98sub prepare_parameters {
99 my $c = shift;
e7c0c583 100
b9e9fff6 101 my @params;
102
103 $c->apache->param->do( sub {
104 my ( $field, $value ) = @_;
105 push( @params, $field, $value );
106 return 1;
107 });
108
bfde09a2 109 $c->request->param(@params);
fc7ec1d9 110}
111
23f9d934 112=item $c->prepare_path
fc7ec1d9 113
114=cut
115
13cafd1a 116# XXX needs fixing, only work with <Location> directive,
6dc87a0f 117# not <Directory> directive
fc7ec1d9 118sub prepare_path {
119 my $c = shift;
6dc87a0f 120 $c->request->path( $c->apache->uri );
121 my $loc = $c->apache->location;
fc7ec1d9 122 no warnings 'uninitialized';
123 $c->req->{path} =~ s/^($loc)?\///;
124 my $base = URI->new;
5ae68c0d 125 $base->scheme( $ENV{HTTPS} ? 'https' : 'http' );
6dc87a0f 126 $base->host( $c->apache->hostname );
127 $base->port( $c->apache->get_server_port );
128 my $path = $c->apache->location;
3803e98f 129 $base->path( $path =~ /\/$/ ? $path : "$path/" );
6dc87a0f 130 $c->request->base( $base->as_string );
fc7ec1d9 131}
132
c9afa5fc 133=item $c->run
134
135=cut
136
e646f111 137sub run { }
138
23f9d934 139=back
140
fc7ec1d9 141=head1 SEE ALSO
142
143L<Catalyst>.
144
145=head1 AUTHOR
146
147Sebastian Riedel, C<sri@cpan.org>
329a7e51 148Christian Hansen C<ch@ngmedia.com>
fc7ec1d9 149
150=head1 COPYRIGHT
151
152This program is free software, you can redistribute it and/or modify it under
153the same terms as Perl itself.
154
155=cut
156
1571;