Skip to content

Commit

Permalink
fix a few proxy bugs in Mojo::UserAgent (closes #1004)
Browse files Browse the repository at this point in the history
  • Loading branch information
kraih committed Oct 16, 2016
1 parent 684b567 commit 70b728c
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 2 deletions.
3 changes: 2 additions & 1 deletion Changes
@@ -1,5 +1,6 @@

7.09 2016-10-06
7.09 2016-10-16
- Fixed a few proxy bugs in Mojo::UserAgent.

7.08 2016-09-23
- Added -i and -o options to get command.
Expand Down
2 changes: 1 addition & 1 deletion lib/Mojo/UserAgent.pm
Expand Up @@ -130,7 +130,7 @@ sub _connect_proxy {
my $id = $tx->connection;
if ($tx->error || !$tx->res->is_status_class(200) || !$tx->keep_alive) {
$old->res->error({message => 'Proxy connection failed'});
$self->_remove($id);
$self->_remove($id) if $id;
return $self->$cb($old);
}

Expand Down
22 changes: 22 additions & 0 deletions t/mojo/websocket_proxy_tls.t
Expand Up @@ -297,4 +297,26 @@ $tx = $ua->get("https://127.0.0.1:$port/proxy");
is $tx->res->code, 200, 'right status';
is $tx->res->body, "https://127.0.0.1:$port/proxy", 'right content';

# Blocking request to bad proxy
$ua = Mojo::UserAgent->new;
$proxy = Mojo::IOLoop::Server->generate_port;
$ua->proxy->https("http://127.0.0.1:$proxy");
$tx = $ua->get("https://127.0.0.1:$port/proxy");
ok !$tx->success, 'no success';
is $tx->error->{message}, 'Proxy connection failed', 'right error';

# Non-blocking request to bad proxy
($success, $err) = ();
$ua->get(
"https://127.0.0.1:$port/proxy" => sub {
my ($ua, $tx) = @_;
$success = $tx->success;
$err = $tx->error;
Mojo::IOLoop->stop;
}
);
Mojo::IOLoop->start;
ok !$success, 'no success';
is $err->{message}, 'Proxy connection failed', 'right error';

done_testing();

0 comments on commit 70b728c

Please sign in to comment.