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