Skip to content

Commit

Permalink
fixed small bug that prevented already prepared IO::Socket::SSL handl…
Browse files Browse the repository at this point in the history
…es to be used by Mojo::UserAgent
  • Loading branch information
kraih committed May 20, 2012
1 parent c8a9113 commit 8655c61
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 3 deletions.
2 changes: 2 additions & 0 deletions Changes
Expand Up @@ -3,6 +3,8 @@
- Added merge method to Mojo::Path.
- Improved documentation.
- Improved tests.
- Fixed small bug that prevented already prepared IO::Socket::SSL handles to
be used by Mojo::UserAgent.
- Fixed small Mojo::URL and Mojo::Path stringification bugs.

2.95 2012-05-10
Expand Down
4 changes: 2 additions & 2 deletions lib/Mojo/IOLoop/Client.pm
Expand Up @@ -2,7 +2,7 @@ package Mojo::IOLoop::Client;
use Mojo::Base 'Mojo::EventEmitter';

use IO::Socket::INET;
use Scalar::Util 'weaken';
use Scalar::Util qw/blessed weaken/;
use Socket qw(IPPROTO_TCP SO_ERROR TCP_NODELAY);

# IPv6 support requires IO::Socket::IP
Expand Down Expand Up @@ -75,7 +75,7 @@ sub _connect {

# TLS
weaken $self;
if ($args->{tls}) {
if ($args->{tls} && !$handle->isa('IO::Socket::SSL')) {

# No TLS support
return $self->emit_safe(
Expand Down
26 changes: 25 additions & 1 deletion t/mojo/user_agent_tls.t
Expand Up @@ -12,7 +12,7 @@ plan skip_all => 'set TEST_TLS to enable this test (developer only!)'
unless $ENV{TEST_TLS};
plan skip_all => 'IO::Socket::SSL 1.37 required for this test!'
unless Mojo::IOLoop::Server::TLS;
plan tests => 19;
plan tests => 22;

# "That does not compute.
# Really?
Expand Down Expand Up @@ -56,6 +56,30 @@ ok $tx->success, 'successful';
is $tx->res->code, 200, 'right status';
is $tx->res->body, 'works!', 'right content';

# Valid certificates (using an already prepared socket)
my $sock;
$ua->ioloop->client(
{
address => 'localhost',
port => $port,
tls => 1,
tls_ca => 't/mojo/certs/ca.crt',
tls_cert => 't/mojo/certs/client.crt',
tls_key => 't/mojo/certs/client.key'
} => sub {
my ($loop, $err, $stream) = @_;
$sock = $stream->steal_handle;
$loop->stop;
}
);
$ua->ioloop->start;
$tx = $ua->build_tx(GET => 'https://lalala/');
$tx->connection($sock);
$ua->start($tx);
ok $tx->success, 'successful';
is $tx->res->code, 200, 'right status';
is $tx->res->body, 'works!', 'right content';

# Valid certificates (env)
$ua = Mojo::UserAgent->new(ioloop => $ua->ioloop);
{
Expand Down

0 comments on commit 8655c61

Please sign in to comment.