Catalyst-Engine-HTTP-POE
view release on metacpan or search on metacpan
0.07 2008-04-05 11:30:00
- Deprecated in favor of HTTP::Prefork.
- Sending SIGHUP to the server will now cause it to restart.
- Sending SIGTERM will now properly shut down the server.
- Removed time prefix from warn calls.
- Allow custom alias to be passed in.
- Added $kernel->call('status') method for retrieving current status.
- Switch to Module::Install.
0.06 2007-02-27 16:00:00
- Keep-alive support.
- Improve performance by buffering header output and sending with the first
chunk of body data.
- Return 400 Bad Request if we can't parse the request properly.
0.05 2006-12-14 13:45:00
- Added support for restart options to match Engine::HTTP.
- Added prefork support.
0.04 2006-12-13 13:40:00
- Fixed bug that would cause simultaneous requests to break if plugins
lib/Catalyst/Engine/HTTP/POE.pm view on Meta::CPAN
our $VERSION = '0.08';
# Enable for helpful debugging information
sub DEBUG () { $ENV{CATALYST_POE_DEBUG} || 0 }
sub BENCH () { $ENV{CATALYST_POE_BENCH} || 0 }
# Max processes (including parent)
sub MAX_PROC () { $ENV{CATALYST_POE_MAX_PROC} || 1 }
# Keep-alive connection timeout in seconds
sub KEEPALIVE_TIMEOUT () { 300 }
# Benchmark::Stopwatch for profiling
if ( BENCH ) {
require Benchmark::Stopwatch;
}
sub run {
my ( $self, $class, @args ) = @_;
lib/Catalyst/Engine/HTTP/POE.pm view on Meta::CPAN
process_input
process
handle_prepare
prepare_done
handle_finalize
finalize_done
client_done
keepalive_timeout
/
],
],
);
return $self;
}
# start the server
sub _start {
lib/Catalyst/Engine/HTTP/POE.pm view on Meta::CPAN
delete $self->{clients}->{$ID};
}
sub read_input {
my ( $kernel, $self, $handle, $ID ) = @_[ KERNEL, OBJECT, ARG0, ARG2 ];
my $client = $self->{clients}->{$ID} || return;
BENCH && $client->{stopwatch}->lap('read_input');
# Clear the keepalive timeout timer if set
if ( my $timer = delete $client->{_timeout_timer} ) {
$kernel->alarm_remove( $timer );
}
# Read some data from the driver
my $driver = $client->{wheel}->[ $client->{wheel}->DRIVER_BOTH ];
my $buffer_ref = $driver->get( $handle );
if ( !$buffer_ref ) {
# Error, stop reading and shut down this client
lib/Catalyst/Engine/HTTP/POE.pm view on Meta::CPAN
my $protocol = 'HTTP/1.0'; # We're not HTTP/1.1 (yet)
my $status = $c->response->status;
my $message = HTTP::Status::status_message($status);
my @headers;
push @headers, "$protocol $status $message";
$c->response->headers->header( Date => HTTP::Date::time2str(time) );
# Some notes: I found that to get keepalive mode to perform well under ab,
# I had to send all data in a single put() call, so the second put in write() below is
# what caused keepalive to be so slow. Not sure if this is just a quirk with ab
# or really a performance problem. :(
# Should we keep the connection open?
my $connection = $c->request->header('Connection');
if ( $connection && $connection =~ /^keep-alive$/i ) {
$c->response->headers->header( Connection => 'keep-alive' );
$client->{_keepalive} = 1;
}
else {
$c->response->headers->header( Connection => 'close' );
}
push @headers, $c->response->headers->as_string("\x0D\x0A");
# Buffer the headers so they are sent with the first write() call
# This reduces the number of TCP packets we are sending
$client->{_header_buf} = join("\x0D\x0A", @headers, '');
lib/Catalyst/Engine/HTTP/POE.pm view on Meta::CPAN
$kernel->yield( 'client_done', $ID );
}
sub client_done {
my ( $kernel, $self, $ID ) = @_[ KERNEL, OBJECT, ARG0 ];
my $client = $self->{clients}->{$ID} || return;
BENCH && warn "[$ID] [$$] Stopwatch:\n" . $client->{stopwatch}->stop->summary;
# clean up everything about this client unless we are using keepalive
if ( $client->{_keepalive} ) {
DEBUG && warn "[$ID] [$$] client_done, keepalive enabled, waiting for more requests\n";
$client->{requests}++;
# Clear important variables from the previous state
delete $client->{_headers};
delete $client->{_written};
delete $client->{_read};
if ( BENCH ) {
$client->{stopwatch} = Benchmark::Stopwatch->new->start;
}
# timeout idle connection after some seconds
$client->{_timeout_timer} = $kernel->delay_set( 'keepalive_timeout', KEEPALIVE_TIMEOUT, $ID );
}
else {
DEBUG && warn "[$ID] [$$] client_done, closing connection\n";
delete $self->{clients}->{$ID};
}
}
sub keepalive_timeout {
my ( $kernel, $self, $ID ) = @_[ KERNEL, OBJECT, ARG0 ];
DEBUG && warn "[$ID] [$$] Timing out idle keepalive connection\n";
delete $self->{clients}->{$ID};
}
# Process a chunk of body data
sub _process_chunk {
my $client = shift;
# Read no more than content-length
my $cl = $client->{env}->{CONTENT_LENGTH} || length( $client->{inputbuf} ) || 0;
t/testapp_poe.pl view on Meta::CPAN
testapp_server.pl [options]
Options:
-d -debug force debug mode
-f -fork handle each request in a new process
(defaults to false)
-? -help display this help and exits
-host host (defaults to all)
-p -port port (defaults to 3000)
-k -keepalive enable keep-alive connections
-r -restart restart when files got modified
(defaults to false)
-rd -restartdelay delay between file checks
-rr -restartregex regex match files that trigger
a restart when modified
(defaults to '\.yml$|\.yaml$|\.pm$')
See also:
perldoc Catalyst::Manual
perldoc Catalyst::Manual::Intro
( run in 3.361 seconds using v1.01-cache-2.11-cpan-39bf76dae61 )