Added $c-req->protocol and $c->req->secure
[catagits/Catalyst-Runtime.git] / lib / Catalyst / Engine / Apache.pm
index a968549..e3c5230 100644 (file)
@@ -18,7 +18,7 @@ See L<Catalyst>.
 
 =head1 DESCRIPTION
 
-This is the Catalyst engine specialized for Apache (i.e. for mod_perl).
+This is a base class engine specialized for Apache (i.e. for mod_perl).
 
 =head1 METHODS
 
@@ -36,13 +36,34 @@ This class overloads some methods from C<Catalyst::Engine>.
 
 =over 4
 
-=item $c->finalize_output
+=item $c->finalize_body
 
 =cut
 
-sub finalize_output {
+sub finalize_body {
     my $c = shift;
-    $c->apache->print( $c->response->output );
+    $c->apache->print( $c->response->body );
+}
+
+=item $c->prepare_body
+
+=cut
+
+sub prepare_body {
+    my $c = shift;
+
+    my $length = $c->request->content_length;
+    my ( $buffer, $content );
+
+    while ($length) {
+
+        $c->apache->read( $buffer, ( $length < 8192 ) ? $length : 8192 );
+
+        $length  -= length($buffer);
+        $content .= $buffer;
+    }
+    
+    $c->request->body($content);
 }
 
 =item $c->prepare_connection
@@ -51,8 +72,13 @@ sub finalize_output {
 
 sub prepare_connection {
     my $c = shift;
-    $c->request->hostname( $c->apache->connection->remote_host );
     $c->request->address( $c->apache->connection->remote_ip );
+    $c->request->hostname( $c->apache->connection->remote_host );
+    $c->request->protocol( $c->apache->protocol );
+    
+    if ( $ENV{HTTPS} ) {
+        $c->request->secure(1);
+    }
 }
 
 =item $c->prepare_headers
@@ -72,17 +98,22 @@ sub prepare_headers {
 sub prepare_parameters {
     my $c = shift;
 
-    foreach my $key ( $c->apache->param ) {
-        my @values = $c->apache->param($key);
-        $c->req->parameters->{$key} = ( @values == 1 ) ? $values[0] : \@values;
-    }
+    my @params;
+    
+    $c->apache->param->do( sub {
+        my ( $field, $value ) = @_;
+        push( @params, $field, $value );
+        return 1;    
+    });
+    
+    $c->request->param(@params);
 }
 
 =item $c->prepare_path
 
 =cut
 
-# XXX needs fixing, only work with <Location> directive, 
+# XXX needs fixing, only work with <Location> directive,
 # not <Directory> directive
 sub prepare_path {
     my $c = shift;
@@ -99,15 +130,6 @@ sub prepare_path {
     $c->request->base( $base->as_string );
 }
 
-=item $c->prepare_request($r)
-
-=cut
-
-sub prepare_request {
-    my ( $c, $r ) = @_;
-    $c->apache( Apache::Request->new($r) );
-}
-
 =item $c->run
 
 =cut
@@ -123,6 +145,7 @@ L<Catalyst>.
 =head1 AUTHOR
 
 Sebastian Riedel, C<sri@cpan.org>
+Christian Hansen C<ch@ngmedia.com>
 
 =head1 COPYRIGHT