Skip to content

Commit

Permalink
failed proxy connections need to set a response error
Browse files Browse the repository at this point in the history
  • Loading branch information
kraih committed Aug 9, 2014
1 parent 922e957 commit 206061b
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 10 deletions.
2 changes: 1 addition & 1 deletion Changes
@@ -1,5 +1,5 @@

5.26 2014-08-08
5.26 2014-08-09
- Improved WebSocket performance.
- Fixed proxy exception handling bug in Mojo::UserAgent.

Expand Down
7 changes: 3 additions & 4 deletions lib/Mojo/UserAgent.pm
Expand Up @@ -139,10 +139,9 @@ sub _connect_proxy {
my ($self, $tx) = @_;

# CONNECT failed (connection needs to be kept alive)
unless ($tx->keep_alive && $tx->res->is_status_class(200)) {
$old->req->error({message => 'Proxy connection failed'});
return $self->$cb($old);
}
$old->res->error({message => 'Proxy connection failed'})
and return $self->$cb($old)
if $tx->error || !$tx->res->is_status_class(200) || !$tx->keep_alive;

# Start real transaction
$old->req->proxy(0);
Expand Down
10 changes: 5 additions & 5 deletions t/mojo/websocket_proxy_tls.t
Expand Up @@ -276,18 +276,18 @@ is $tx->res->body, "https://localhost:$port/proxy", 'right content';
# Proxy WebSocket with bad target
$ua->proxy->https("http://localhost:$proxy");
my $port2 = $port + 1;
my ($success, $err);
$result = undef;
$ua->websocket(
"wss://localhost:$port2/test" => sub {
my ($ua, $tx) = @_;
$success = $tx->success;
$err = $tx->error;
$result = $tx;
Mojo::IOLoop->stop;
}
);
Mojo::IOLoop->start;
ok !$success, 'no success';
is $err->{message}, 'Proxy connection failed', 'right error';
ok !$result->success, 'no success';
is $result->res->error->{message}, 'Proxy connection failed', 'right error';
is $result->error->{message}, 'Proxy connection failed', 'right error';

# Failed TLS handshake through proxy
$tx = $ua->get("https://localhost:$fake");
Expand Down

0 comments on commit 206061b

Please sign in to comment.