Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
handle CONNECT failures a little more gracefully
  • Loading branch information
kraih committed Jul 7, 2013
1 parent af05ad5 commit ba0f0dd
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 12 deletions.
2 changes: 1 addition & 1 deletion Changes
@@ -1,5 +1,5 @@

4.18 2013-07-06
4.18 2013-07-07

4.17 2013-07-04
- Updated jQuery to version 2.0.3.
Expand Down
6 changes: 3 additions & 3 deletions lib/Mojo/UserAgent.pm
Expand Up @@ -197,18 +197,18 @@ sub _connect_proxy {
my ($self, $tx) = @_;

# CONNECT failed
unless (($tx->res->code // '') eq '200') {
unless ($tx->keep_alive && ($tx->res->code // '') eq '200') {
$old->req->error('Proxy connection failed');
return $self->_finish($old, $cb);
}

# Prevent proxy reassignment and start real transaction
$old->req->proxy(0);
return $self->_start($old->connection($tx->connection), $cb)
my $id = $tx->connection;
return $self->_start($old->connection($id), $cb)
unless $tx->req->url->protocol eq 'https';

# TLS upgrade
return unless my $id = $tx->connection;
my $loop = $self->_loop;
my $handle = $loop->stream($id)->steal_handle;
my $c = delete $self->{connections}{$id};
Expand Down
6 changes: 3 additions & 3 deletions t/mojo/websocket_proxy.t
Expand Up @@ -124,7 +124,7 @@ Mojo::IOLoop->server(
my $result;
$ua->get(
"http://localhost:$port/" => sub {
$result = pop->success->body;
$result = pop->res->body;
Mojo::IOLoop->stop;
}
);
Expand Down Expand Up @@ -158,7 +158,7 @@ $ua->get(
'http://example.com/proxy' => sub {
my ($ua, $tx) = @_;
$kept_alive = $tx->kept_alive;
$result = $tx->success->body;
$result = $tx->res->body;
Mojo::IOLoop->stop;
}
);
Expand Down Expand Up @@ -190,7 +190,7 @@ is $result, 'test1test2', 'right result';
# Blocking proxy request
my $tx = $ua->get('http://example.com/proxy');
is $tx->res->code, 200, 'right status';
is $tx->success->body, 'http://example.com/proxy', 'right content';
is $tx->res->body, 'http://example.com/proxy', 'right content';

# Proxy WebSocket
$ua = Mojo::UserAgent->new(http_proxy => "http://localhost:$proxy");
Expand Down
10 changes: 5 additions & 5 deletions t/mojo/websocket_proxy_tls.t
Expand Up @@ -151,7 +151,7 @@ my $ua = Mojo::UserAgent->new(
my $result;
$ua->get(
"https://localhost:$port/" => sub {
$result = pop->success->body;
$result = pop->res->body;
Mojo::IOLoop->stop;
}
);
Expand All @@ -171,7 +171,7 @@ my $works;
$ua->max_redirects(3)->get(
"https://localhost:$port/broken_redirect" => sub {
my ($ua, $tx) = @_;
$result = $tx->success->body;
$result = $tx->res->body;
$works = $tx->res->headers->header('X-Works');
Mojo::IOLoop->stop;
}
Expand Down Expand Up @@ -208,7 +208,7 @@ my ($auth, $kept_alive);
$ua->get(
"https://localhost:$port/proxy" => sub {
my ($ua, $tx) = @_;
$result = $tx->success->body;
$result = $tx->res->body;
$auth = $tx->req->headers->proxy_authorization;
$kept_alive = $tx->kept_alive;
Mojo::IOLoop->stop;
Expand All @@ -225,7 +225,7 @@ $ua->get(
"https://localhost:$port/proxy" => sub {
my ($ua, $tx) = @_;
$kept_alive = $tx->kept_alive;
$result = $tx->success->body;
$result = $tx->res->body;
Mojo::IOLoop->stop;
}
);
Expand Down Expand Up @@ -262,7 +262,7 @@ ok $sent > 25, 'sent enough';
$ua->https_proxy("http://sri:secr3t\@localhost:$proxy");
my $tx = $ua->get("https://localhost:$port/proxy");
is $tx->res->code, 200, 'right status';
is $tx->success->body, "https://localhost:$port/proxy", 'right content';
is $tx->res->body, "https://localhost:$port/proxy", 'right content';

# Proxy WebSocket with bad target
$ua->https_proxy("http://localhost:$proxy");
Expand Down

0 comments on commit ba0f0dd

Please sign in to comment.