package Catalyst::Engine::Test;
use strict;
-use base 'Catalyst::Engine::CGI::NPH';
+use base 'Catalyst::Engine::HTTP::Base';
-use HTTP::Request;
-use HTTP::Response;
-use IO::File;
-use URI;
+use Catalyst::Utils;
=head1 NAME
=head1 OVERLOADED METHODS
-This class overloads some methods from C<Catalyst::Engine::CGI::NPH>.
+This class overloads some methods from C<Catalyst::Engine::HTTP::Base>.
=over 4
=cut
sub run {
- my $class = shift;
- my $request = shift || '/';
+ my ( $class, $request ) = @_;
+
+ $request = Catalyst::Utils::request($request);
- unless ( ref $request ) {
- $request = URI->new( $request, 'http' );
- }
- unless ( ref $request eq 'HTTP::Request' ) {
- $request = HTTP::Request->new( 'GET', $request );
- }
+ $request->header(
+ 'Host' => sprintf( '%s:%d', $request->uri->host, $request->uri->port )
+ );
- local ( *STDIN, *STDOUT );
-
- my %clean = %ENV;
- my $output = '';
- $ENV{CONTENT_TYPE} ||= $request->header('Content-Type') || '';
- $ENV{CONTENT_LENGTH} ||= $request->header('Content-Length') || '';
- $ENV{GATEWAY_INTERFACE} ||= 'CGI/1.1';
- $ENV{HTTP_USER_AGENT} ||= 'Catalyst';
- $ENV{HTTP_HOST} ||= $request->uri->host || 'localhost';
- $ENV{QUERY_STRING} ||= $request->uri->query || '';
- $ENV{REQUEST_METHOD} ||= $request->method;
- $ENV{PATH_INFO} ||= $request->uri->path || '/';
- $ENV{SCRIPT_NAME} ||= '/';
- $ENV{SERVER_NAME} ||= $request->uri->host || 'localhost';
- $ENV{SERVER_PORT} ||= $request->uri->port;
- $ENV{SERVER_PROTOCOL} ||= 'HTTP/1.1';
-
- for my $field ( $request->header_field_names ) {
- if ( $field =~ /^Content-(Length|Type)$/ ) {
- next;
- }
- $field =~ s/-/_/g;
- $ENV{ 'HTTP_' . uc($field) } = $request->header($field);
- }
+ my $http = Catalyst::Engine::HTTP::Base::struct->new(
+ address => '127.0.0.1',
+ hostname => 'localhost',
+ request => $request,
+ response => HTTP::Response->new
+ );
- if ( $request->content_length ) {
- my $body = IO::File->new_tmpfile;
- $body->print( $request->content ) or die $!;
- $body->seek( 0, SEEK_SET ) or die $!;
- open( STDIN, "<&=", $body->fileno )
- or die("Failed to dup \$body: $!");
- }
+ $http->response->date(time);
+
+ $class->handler($http);
- open( STDOUT, '>', \$output );
- $class->handler;
- %ENV = %clean;
- return HTTP::Response->parse($output);
+ return $http->response;
}
=back