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