Skip to content

Commit

Permalink
Check for HTTP errors after attempting to cache connection for reuse
Browse files Browse the repository at this point in the history
proposed fix for #935
  • Loading branch information
jberger committed Mar 12, 2016
1 parent dd66d84 commit a999f69
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
6 changes: 3 additions & 3 deletions lib/Mojo/UserAgent.pm
Expand Up @@ -223,9 +223,6 @@ sub _finish {
if ($close && !$res->code && !$res->error) {
$res->error({message => 'Premature connection close'});
}
elsif ($res->is_status_class(400) || $res->is_status_class(500)) {
$res->error({message => $res->message, code => $res->code});
}

# Always remove connection for WebSockets
return $self->_remove($id) if $old->is_websocket;
Expand All @@ -242,6 +239,9 @@ sub _finish {

# Finish connection and handle redirects
$self->_reuse($id, $close);
if ($res->is_status_class(400) || $res->is_status_class(500)) {
$res->error({message => $res->message, code => $res->code});
}
$c->{cb}($self, $old) unless $self->_redirect($c, $old);
}

Expand Down
8 changes: 8 additions & 0 deletions t/mojo/user_agent.t
Expand Up @@ -362,7 +362,15 @@ ok $tx->res->is_limit_exceeded, 'limit is exceeded';

# 404 response
$tx = $ua->get('/does_not_exist');
ok !$tx->success, 'not successful';
ok !$tx->kept_alive, 'kept connection not alive';
ok $tx->keep_alive, 'keep connection alive';
is $tx->error->{message}, 'Not Found', 'right error';
is $tx->error->{code}, 404, 'right status';
$tx = $ua->get('/does_not_exist');
ok !$tx->success, 'not successful';
ok $tx->kept_alive, 'kept connection alive';
ok $tx->keep_alive, 'keep connection alive';
is $tx->error->{message}, 'Not Found', 'right error';
is $tx->error->{code}, 404, 'right status';

Expand Down

0 comments on commit a999f69

Please sign in to comment.