fixed a bug in https detection
[catagits/Catalyst-Runtime.git] / lib / Catalyst / Engine / CGI / Base.pm
index bc4ef87..6e19c60 100644 (file)
@@ -3,12 +3,9 @@ package Catalyst::Engine::CGI::Base;
 use strict;
 use base 'Catalyst::Engine';
 
-use IO::File ();
 use URI;
 use URI::http;
 
-__PACKAGE__->mk_accessors('cgi');
-
 =head1 NAME
 
 Catalyst::Engine::CGI::Base - Base class for CGI Engines
@@ -17,16 +14,6 @@ Catalyst::Engine::CGI::Base - Base class for CGI Engines
 
 This is a base class for CGI engines.
 
-=head1 METHODS
-
-=over 4
-
-=item $c->cgi
-
-This config parameter contains the C<CGI> object.
-
-=back
-
 =head1 OVERLOADED METHODS
 
 This class overloads some methods from C<Catalyst::Engine>.
@@ -64,10 +51,9 @@ sub finalize_headers {
 sub prepare_body {
     my $c = shift;
     
-    my $handle = IO::File->new_from_fd( fileno(STDIN), IO::File::O_RDONLY );
-    my $body   = undef;  
+    my $body = undef;
     
-    while ( $handle->sysread( my $buffer, 8192 ) ) {
+    while ( read( STDIN, my $buffer, 8192 ) ) {
         $body .= $buffer;
     }
     
@@ -83,8 +69,13 @@ sub prepare_connection {
     $c->request->address( $ENV{REMOTE_ADDR} );
     $c->request->hostname( $ENV{REMOTE_HOST} );
     $c->request->protocol( $ENV{SERVER_PROTOCOL} );
+    $c->request->user( $ENV{REMOTE_USER} );
+
+    if ( $ENV{HTTPS} && uc( $ENV{HTTPS} ) eq 'ON' ) {
+        $c->request->secure(1);
+    }
 
-    if ( $ENV{HTTPS} || $ENV{SERVER_PORT} == 443 ) {
+    if ( $ENV{SERVER_PORT} == 443 ) {
         $c->request->secure(1);
     }
 }
@@ -135,7 +126,9 @@ sub prepare_path {
         $base = $base->canonical->as_string;
     }
 
+    my $location = $ENV{SCRIPT_NAME} || '/';
     my $path = $ENV{PATH_INFO} || '/';
+    $path =~ s/^($location)?\///;
     $path =~ s/%([0-9A-Fa-f]{2})/chr(hex($1))/eg;
     $path =~ s/^\///;
 
@@ -147,7 +140,7 @@ sub prepare_path {
 
 =cut
 
-sub run { shift->handler }
+sub run { shift->handler(@_) }
 
 =back