1 package Catalyst::Engine::CGI::Base;
4 use base 'Catalyst::Engine';
11 Catalyst::Engine::CGI::Base - Base class for CGI Engines
15 This is a base class for CGI engines.
17 =head1 OVERLOADED METHODS
19 This class overloads some methods from C<Catalyst::Engine>.
23 =item $c->finalize_body
25 Prints the response output to STDOUT.
31 print $c->response->output;
34 =item $c->finalize_headers
38 sub finalize_headers {
41 $c->response->header( Status => $c->response->status );
43 print $c->response->headers->as_string("\015\012");
47 =item $c->prepare_body
56 while ( read( STDIN, my $buffer, 8192 ) ) {
60 $c->request->body($body);
63 =item $c->prepare_connection
67 sub prepare_connection {
69 $c->request->address( $ENV{REMOTE_ADDR} );
70 $c->request->hostname( $ENV{REMOTE_HOST} );
71 $c->request->protocol( $ENV{SERVER_PROTOCOL} );
73 if ( $ENV{HTTPS} || $ENV{SERVER_PORT} == 443 ) {
74 $c->request->secure(1);
78 =item $c->prepare_headers
85 while ( my ( $header, $value ) = each %ENV ) {
87 next unless $header =~ /^(HTTP|CONTENT)/i;
89 ( my $field = $header ) =~ s/^HTTPS?_//;
91 $c->req->headers->header( $field => $value );
94 $c->req->method( $ENV{REQUEST_METHOD} || 'GET' );
97 =item $c->prepare_path
106 my $scheme = $c->request->secure ? 'https' : 'http';
107 my $host = $ENV{HTTP_HOST} || $ENV{SERVER_NAME};
108 my $port = $ENV{SERVER_PORT} || 80;
109 my $path = $ENV{SCRIPT_NAME} || '/';
111 unless ( $path =~ /\/$/ ) {
116 $base->scheme($scheme);
121 $base = $base->canonical->as_string;
124 my $path = $ENV{PATH_INFO} || '/';
125 $path =~ s/%([0-9A-Fa-f]{2})/chr(hex($1))/eg;
128 $c->req->base($base);
129 $c->req->path($path);
136 sub run { shift->handler }
146 Sebastian Riedel, C<sri@cpan.org>
147 Christian Hansen, C<ch@ngmedia.com>
151 This program is free software, you can redistribute it and/or modify it under
152 the same terms as Perl itself.