Permalink
Browse files

improved built-in web servers to log inactivity timeouts as debug mes…

…sages instead of errors
  • Loading branch information...
1 parent a51b932 commit a36c1628f30dd413e1bb363750d1ca3b457b8a38 @kraih committed May 7, 2012
Showing with 15 additions and 23 deletions.
  1. +3 −1 Changes
  2. +9 −18 lib/Mojo/Server/Daemon.pm
  3. +1 −2 lib/Mojo/UserAgent.pm
  4. +1 −1 t/mojo/user_agent.t
  5. +1 −1 t/mojo/websocket.t
View
@@ -1,8 +1,10 @@
This file documents the revision history for Perl extension Mojolicious.
-2.94 2012-05-06
+2.94 2012-05-07
- Added support for 308 redirects to Mojo::UserAgent.
- Added support for new HTTP status codes.
+ - Improved built-in web servers to log inactivity timeouts as debug messages
+ instead of errors.
- Improved documentation.
- Fixed typo in 414 status message.
- Fixed small backlog bug in Mojo::Server::Daemon.
View
@@ -61,8 +61,7 @@ sub _build_tx {
my ($self, $id, $c) = @_;
# Build transaction
- my $tx = $self->build_tx;
- $tx->connection($id);
+ my $tx = $self->build_tx->connection($id);
# Identify
$tx->res->headers->server('Mojolicious (Perl)');
@@ -98,14 +97,6 @@ sub _build_tx {
return $tx;
}
-sub _close { shift->_remove(pop) }
-
-sub _error {
- my ($self, $id, $err) = @_;
- $self->app->log->error($err);
- $self->_remove($id);
-}
-
sub _finish {
my ($self, $id, $tx) = @_;
@@ -187,19 +178,19 @@ sub _listen {
$stream->timeout($self->inactivity_timeout);
# Events
+ $stream->on(close => sub { $self->_remove($id) });
$stream->on(
- timeout => sub {
- $self->_error($id => 'Inactivity timeout.')
- if $self->{connections}{$id}{tx};
+ error => sub {
+ $self->app->log->error(pop);
+ $self->_remove($id);
}
);
- $stream->on(close => sub { $self->_close($id) });
- $stream->on(error => sub { $self->_error($id => pop) });
- $stream->on(read => sub { $self->_read($id => pop) });
+ $stream->on(read => sub { $self->_read($id => pop) });
+ $stream->on(
+ timeout => sub { $self->app->log->debug('Inactivity timeout.') });
}
);
- $self->{listening} ||= [];
- push @{$self->{listening}}, $id;
+ push @{$self->{listening} ||= []}, $id;
# Bonjour
if (BONJOUR && (my $p = Net::Rendezvous::Publish->new)) {
View
@@ -254,8 +254,7 @@ sub _connected {
$loop->stream($id)->timeout($self->inactivity_timeout);
# Store connection information in transaction
- my $tx = $self->{connections}{$id}{tx};
- $tx->connection($id);
+ my $tx = $self->{connections}{$id}{tx}->connection($id);
my $handle = $loop->stream($id)->handle;
$tx->local_address($handle->sockhost)->local_port($handle->sockport);
$tx->remote_address($handle->peerhost)->remote_port($handle->peerport);
View
@@ -189,7 +189,7 @@ is $tx->res->body, 'works!', 'right content';
my $log = '';
$message = app->log->subscribers('message')->[0];
app->log->unsubscribe(message => $message);
-app->log->level('error');
+app->log->level('debug');
app->log->on(message => sub { $log .= pop });
$tx = $ua->get('/timeout?timeout=0.5');
app->log->level('fatal');
View
@@ -484,7 +484,7 @@ is $result, 'hi!' x 100, 'right result';
my $log = '';
$message = app->log->subscribers('message')->[0];
app->log->unsubscribe(message => $message);
-app->log->level('error');
+app->log->level('debug');
app->log->on(message => sub { $log .= pop });
$ua->websocket(
'/timeout' => sub {

0 comments on commit a36c162

Please sign in to comment.