Skip to content

Commit

Permalink
fixed HTTPS proxy bug in Mojo::UserAgent
Browse files Browse the repository at this point in the history
  • Loading branch information
kraih committed Oct 21, 2011
1 parent 7fd6f62 commit 2d2233c
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 5 deletions.
3 changes: 3 additions & 0 deletions Changes
@@ -1,5 +1,8 @@
This file documents the revision history for Perl extension Mojolicious.

2.05 2011-10-22 00:00:00
- Fixed HTTPS proxy bug in Mojo::UserAgent.

2.04 2011-10-21 00:00:00
- Improved documentation.
- Fixed small HTTP response parser bug.
Expand Down
18 changes: 18 additions & 0 deletions lib/Mojo/IOLoop.pm
Expand Up @@ -887,10 +887,28 @@ Start the loop, this will block until C<stop> is called.
=head2 C<start_tls>
$loop->start_tls($id);
$loop->start_tls($id => {
tls_cert => '/foo/client.cert',
tls_key => '/foo/client.key'
});
Start new TLS connection inside old connection.
Note that TLS support depends on L<IO::Socket::SSL>.
These options are currently available:
=over 2
=item C<tls_cert>
Path to the TLS certificate file.
=item C<tls_key>
Path to the TLS key file.
=back
=head2 C<stop>
Mojo::IOLoop->stop;
Expand Down
3 changes: 2 additions & 1 deletion lib/Mojo/UserAgent.pm
Expand Up @@ -393,7 +393,8 @@ sub _proxy_connect {
# TLS upgrade
if ($tx->req->url->scheme eq 'https') {
return unless my $id = $tx->connection;
$self->_loop->start_tls($id);
$self->_loop->start_tls(
$id => {tls_cert => $self->cert, tls_key => $self->key});
$old->req->proxy(undef);
}

Expand Down
2 changes: 1 addition & 1 deletion lib/Mojolicious.pm
Expand Up @@ -35,7 +35,7 @@ has static => sub { Mojolicious::Static->new };
has types => sub { Mojolicious::Types->new };

our $CODENAME = 'Leaf Fluttering In Wind';
our $VERSION = '2.04';
our $VERSION = '2.05';

# "These old doomsday devices are dangerously unstable.
# I'll rest easier not knowing where they are."
Expand Down
8 changes: 5 additions & 3 deletions t/mojo/websocket_proxy_tls.t
Expand Up @@ -65,8 +65,10 @@ websocket '/test' => sub {
my $ua = Mojo::UserAgent->new;
my $daemon =
Mojo::Server::Daemon->new(app => app, ioloop => Mojo::IOLoop->singleton);
my $port = Mojo::IOLoop->new->generate_port;
$daemon->listen(["https://*:$port"]);
my $port = Mojo::IOLoop->new->generate_port;
my $listen = "https://*:$port:t/mojo/certs/server.crt"
. ':t/mojo/certs/server.key:t/mojo/certs/ca.crt';
$daemon->listen([$listen]);
$daemon->prepare_ioloop;

# Connect proxy server for testing
Expand Down Expand Up @@ -127,7 +129,7 @@ Mojo::IOLoop->listen(

# GET / (normal request)
my $result;
$ua->get(
$ua->cert('t/mojo/certs/client.crt')->key('t/mojo/certs/client.key')->get(
"https://localhost:$port/" => sub {
$result = pop->success->body;
Mojo::IOLoop->stop;
Expand Down

0 comments on commit 2d2233c

Please sign in to comment.