Skip to content

Commit

Permalink
cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
kraih committed Jan 26, 2011
1 parent 0429168 commit 0daf5af
Showing 1 changed file with 20 additions and 18 deletions.
38 changes: 20 additions & 18 deletions lib/Mojo/Client.pm
Expand Up @@ -744,33 +744,35 @@ sub _connected {
sub _drop {
my ($self, $id) = @_;

# Keep alive
my $tx = $self->{_cs}->{$id}->{tx};
if ($tx && $tx->keep_alive && !$tx->error) {
# Drop connection
my $c = delete $self->{_cs}->{$id};

# Transaction
my $tx = $c->{tx};
if ($tx && $tx->keep_alive) {

# Response
my $res = $tx->res;

# Don't keep CONNECTed connections alive
my $method = $tx->req->method || '';
my $code = $res->code || '';
unless ($method =~ /^connect$/i && $code eq '200') {
# Interrupted
$res->error('Interrupted, maybe a timeout?') unless $res->is_done;

# No errors
unless ($tx->error) {

# Keep non-CONNECTed connection alive
$self->_cache(join(':', $self->_tx_info($tx)), $id)
unless (($tx->req->method || '') =~ /^connect$/i
&& ($res->code || '') eq '200');

# Keep connection alive
!$res->is_done && $tx->keep_alive
? $res->error('Interrupted, maybe a timeout?')
: $self->_cache(join(':', $self->_tx_info($tx)), $id);
# Still active
return;
}
}

# Connection close
else {
$self->_cache($id);
$self->ioloop->drop($id);
}

# Drop connection
delete $self->{_cs}->{$id};
$self->_cache($id);
$self->ioloop->drop($id);
}

sub _error {
Expand Down

0 comments on commit 0daf5af

Please sign in to comment.