1 package Catalyst::Engine::CGI::Base;
4 use base 'Catalyst::Engine';
10 __PACKAGE__->mk_accessors('cgi');
14 Catalyst::Engine::CGI::Base - Base class for CGI Engines
18 This is a base class for CGI engines.
26 This config parameter contains the C<CGI> object.
30 =head1 OVERLOADED METHODS
32 This class overloads some methods from C<Catalyst::Engine>.
36 =item $c->finalize_body
38 Prints the response output to STDOUT.
44 print $c->response->output;
47 =item $c->finalize_headers
51 sub finalize_headers {
54 $c->response->header( Status => $c->response->status );
56 print $c->response->headers->as_string("\015\012");
60 =item $c->prepare_body
67 my $handle = IO::File->new_from_fd( fileno(STDIN), IO::File::O_RDONLY );
70 while ( $handle->sysread( my $buffer, 8192 ) ) {
74 $c->request->body($body);
77 =item $c->prepare_connection
81 sub prepare_connection {
83 $c->request->address( $ENV{REMOTE_ADDR} );
84 $c->request->hostname( $ENV{REMOTE_HOST} );
85 $c->request->protocol( $ENV{SERVER_PROTOCOL} );
87 if ( $ENV{HTTPS} || $ENV{SERVER_PORT} == 443 ) {
88 $c->request->secure(1);
92 =item $c->prepare_headers
99 while ( my ( $header, $value ) = each %ENV ) {
101 next unless $header =~ /^(HTTP|CONTENT)/i;
103 ( my $field = $header ) =~ s/^HTTPS?_//;
105 $c->req->headers->header( $field => $value );
108 $c->req->method( $ENV{REQUEST_METHOD} || 'GET' );
111 =item $c->prepare_path
120 my $scheme = $c->request->secure ? 'https' : 'http';
121 my $host = $ENV{HTTP_HOST} || $ENV{SERVER_NAME};
122 my $port = $ENV{SERVER_PORT} || 80;
123 my $path = $ENV{SCRIPT_NAME} || '/';
125 unless ( $path =~ /\/$/ ) {
130 $base->scheme($scheme);
135 $base = $base->canonical->as_string;
138 my $path = $ENV{PATH_INFO} || '/';
139 $path =~ s/%([0-9A-Fa-f]{2})/chr(hex($1))/eg;
142 $c->req->base($base);
143 $c->req->path($path);
150 sub run { shift->handler }
160 Sebastian Riedel, C<sri@cpan.org>
161 Christian Hansen, C<ch@ngmedia.com>
165 This program is free software, you can redistribute it and/or modify it under
166 the same terms as Perl itself.