Fixed MP engines, only load what we need
[catagits/Catalyst-Runtime.git] / lib / Catalyst / Engine / Apache / MP19.pm
1 package Catalyst::Engine::Apache::MP19;
2
3 use strict;
4 use base 'Catalyst::Engine::Apache::Base';
5
6 use Apache2             ();
7 use Apache::Connection  ();
8 use Apache::Const       ();
9 use Apache::RequestIO   ();
10 use Apache::RequestRec  ();
11 use Apache::RequestUtil ();
12 use Apache::Request     ();
13 use Apache::Upload      ();
14
15 Apache::Const->import( -compile => ':common' );
16
17 =head1 NAME
18
19 Catalyst::Engine::Apache::MP19 - Catalyst Apache MP19 Engine
20
21 =head1 SYNOPSIS
22
23 See L<Catalyst>.
24
25 =head1 DESCRIPTION
26
27 This is the Catalyst engine specialized for Apache mod_perl version 1.9x.
28
29 =head1 OVERLOADED METHODS
30
31 This class overloads some methods from C<Catalyst::Engine::Apache::Base>.
32
33 =over 4
34
35 =item $c->finalize_headers
36
37 =cut
38
39 sub finalize_headers {
40     my $c = shift;
41
42     for my $name ( $c->response->headers->header_field_names ) {
43         next if $name =~ /Content-Type/i;
44         my @values = $c->response->header($name);
45         $c->apache->headers_out->add( $name => $_ ) for @values;
46     }
47
48     if ( $c->response->header('Set-Cookie') && $c->response->status >= 300 ) {
49         my @values = $c->response->header('Set-Cookie');
50         $c->apache->err_headers_out->add( 'Set-Cookie' => $_ ) for @values;
51     }
52
53     $c->apache->status( $c->response->status );
54     $c->apache->content_type( $c->response->header('Content-Type') );
55
56     return 0;
57 }
58
59 =item $c->handler
60
61 =cut
62
63 sub handler : method {
64     shift->SUPER::handler(@_);
65 }
66
67 =item $c->prepare_request($r)
68
69 =cut
70
71 sub prepare_request {
72     my ( $c, $r ) = @_;
73     $c->apache( Apache::Request->new($r) );
74 }
75
76 =item $c->prepare_uploads
77
78 =cut
79
80 sub prepare_uploads {
81     my $c = shift;
82
83     # This is a workaround for a know bug with libapreq <= 2.0.4
84     # http://svn.apache.org/viewcvs.cgi?rev=122925&view=rev
85     
86     my @uploads;    
87
88     for my $field ( $c->request->param ) {
89
90         for my $upload ( $c->apache->upload($field) ) {
91
92             my $object = Catalyst::Request::Upload->new(
93                 filename => $upload->filename,
94                 size     => $upload->size,
95                 tempname => $upload->tempname,
96                 type     => $upload->type
97             );
98
99             push( @uploads, $field, $object );
100         }
101     }
102
103     $c->request->upload(@uploads);
104 }
105
106 =back
107
108 =head1 SEE ALSO
109
110 L<Catalyst>, L<Catalyst::Engine>, L<Catalyst::Engine::Apache::Base>.
111
112 =head1 AUTHOR
113
114 Sebastian Riedel, C<sri@cpan.org>
115 Christian Hansen C<ch@ngmedia.com>
116
117 =head1 COPYRIGHT
118
119 This program is free software, you can redistribute it and/or modify it under
120 the same terms as Perl itself.
121
122 =cut
123
124 1;