1 package Catalyst::Engine::Apache;
5 use constant MP2 => $mod_perl::VERSION >= 1.99;
6 use base 'Catalyst::Engine';
12 require Apache::RequestIO;
13 require Apache::RequestRec;
14 require Apache::SubRequest;
15 require Apache::RequestUtil;
19 else { require Apache }
22 require Apache::Request;
23 require Apache::Cookie;
24 require Apache::Upload if MP2;
26 __PACKAGE__->mk_accessors(qw/apache_request original_request/);
30 Catalyst::Engine::Apache - Catalyst Apache Engine
44 Returns an C<Apache::Request> object.
46 =head3 original_request
48 Returns the original Apache request object.
50 =head2 OVERLOADED METHODS
52 This class overloads some methods from C<Catalyst::Engine>.
54 =head3 finalize_headers
58 sub finalize_headers {
60 for my $name ( $c->response->headers->header_field_names ) {
61 next if $name =~ /Content-Type/i;
62 $c->original_request->headers_out->set(
63 $name => $c->response->headers->header($name) );
65 while ( my ( $name, $cookie ) = each %{ $c->response->cookies } ) {
66 my %cookie = ( -name => $name, -value => $cookie->{value} );
67 $cookie->{-expires} = $cookie->{expires} if $cookie->{expires};
68 $cookie->{-domain} = $cookie->{domain} if $cookie->{domain};
69 $cookie->{-path} = $cookie->{path} if $cookie->{path};
70 $cookie->{-secure} = $cookie->{secure} if $cookie->{secure};
71 my $cookie = Apache::Cookie->new( $c->original_request, %cookie );
73 ? $c->apache_request->err_headers_out->add(
74 'Set-Cookie' => $cookie->as_string )
77 $c->original_request->status( $c->response->status );
78 $c->original_request->content_type( $c->response->headers->content_type
80 MP2 || $c->apache_request->send_http_header;
84 =head3 finalize_output
90 $c->original_request->print( $c->response->{output} );
93 =head3 prepare_cookies
100 ? $c->req->cookies( { Apache::Cookie->fetch } )
102 { Apache::Cookie->new( $c->apache_request )->fetch } );
105 =head3 prepare_headers
109 sub prepare_headers {
111 $c->req->method( $c->apache_request->method );
112 $c->req->headers->header( %{ $c->apache_request->headers_in } );
115 =head3 prepare_parameters
119 sub prepare_parameters {
122 foreach my $key ( $c->apache_request->param ) {
123 my @values = $c->apache_request->param($key);
124 $args{$key} = @values == 1 ? $values[0] : \@values;
126 $c->req->parameters( \%args );
135 $c->req->path( $c->apache_request->uri );
136 my $loc = $c->apache_request->location;
137 no warnings 'uninitialized';
138 $c->req->{path} =~ s/^($loc)?\///;
140 $base->scheme( $c->apache_request->protocol =~ /HTTPS/ ? 'https' : 'http' );
141 $base->host( $c->apache_request->hostname );
142 $base->port( $c->apache_request->get_server_port );
143 $base->path( $c->apache_request->location );
144 $c->req->base( $base->as_string );
147 =head3 prepare_request
151 sub prepare_request {
153 $c->apache_request( Apache::Request->new($r) );
154 $c->original_request($r);
157 =head3 prepare_uploads
161 sub prepare_uploads {
163 for my $upload ( $c->apache_request->upload ) {
164 $upload = $c->apache_request->upload($upload) if MP2;
165 $c->req->uploads->{ $upload->filename } = {
167 size => $upload->size,
168 type => $upload->type
179 Sebastian Riedel, C<sri@cpan.org>
183 This program is free software, you can redistribute it and/or modify it under
184 the same terms as Perl itself.