Skip to content

Commit

Permalink
added workaround to make IO::Socket::SSL work with IO::Socket::IP
Browse files Browse the repository at this point in the history
  • Loading branch information
kraih committed May 26, 2012
1 parent 9c72c82 commit 3578ae6
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 8 deletions.
1 change: 1 addition & 0 deletions Changes
@@ -1,5 +1,6 @@

2.97 2012-05-26
- Added workaround to make IO::Socket::SSL work with IO::Socket::IP.
- Improved documentation.
- Improved tests.
- Fixed bug that prevented Test::Mojo from working with normal Mojolicious
Expand Down
3 changes: 3 additions & 0 deletions lib/Mojo/IOLoop/Client.pm
Expand Up @@ -17,6 +17,9 @@ use constant TLS => $ENV{MOJO_NO_TLS}
use constant TLS_READ => TLS ? IO::Socket::SSL::SSL_WANT_READ() : 0;
use constant TLS_WRITE => TLS ? IO::Socket::SSL::SSL_WANT_WRITE() : 0;

# Fix IO::Socket::SSL to work with IO::Socket::IP
$IO::Socket::SSL::ISA[0] = 'IO::Socket::IP' if IPV6;

# "It's like my dad always said: eventually, everybody gets shot."
has reactor => sub {
require Mojo::IOLoop;
Expand Down
3 changes: 3 additions & 0 deletions lib/Mojo/IOLoop/Server.pm
Expand Up @@ -20,6 +20,9 @@ use constant TLS => $ENV{MOJO_NO_TLS}
use constant TLS_READ => TLS ? IO::Socket::SSL::SSL_WANT_READ() : 0;
use constant TLS_WRITE => TLS ? IO::Socket::SSL::SSL_WANT_WRITE() : 0;

# Fix IO::Socket::SSL to work with IO::Socket::IP
$IO::Socket::SSL::ISA[0] = 'IO::Socket::IP' if IPV6;

# To regenerate the certificate run this command (18.04.2012)
# openssl req -new -x509 -keyout server.key -out server.crt -nodes -days 7300
my $CERT = catfile dirname(__FILE__), 'server.crt';
Expand Down
17 changes: 9 additions & 8 deletions t/mojo/user_agent_online.t
Expand Up @@ -14,7 +14,7 @@ plan skip_all => 'IO::Socket::IP 0.06 required for this test!'
unless Mojo::IOLoop::Server::IPV6;
plan skip_all => 'IO::Socket::SSL 1.37 required for this test!'
unless Mojo::IOLoop::Server::TLS;
plan tests => 86;
plan tests => 84;

# "So then I said to the cop, "No, you're driving under the influence...
# of being a jerk"."
Expand Down Expand Up @@ -201,18 +201,19 @@ is $tx->req->method, 'GET', 'right method';
is $tx->req->url, 'https://www.metacpan.org', 'right url';
is $tx->res->code, 200, 'right status';

# HTTPS request that requires IPv6
$tx = $ua->get('https://ipv6.google.com');
is $tx->req->method, 'GET', 'right method';
is $tx->req->url, 'https://ipv6.google.com', 'right url';
is $tx->res->code, 200, 'right status';

# HTTPS request that requires SNI
$tx = $ua->get('https://google.de');
like $ua->ioloop->stream($tx->connection)
->handle->peer_certificate('commonName'), qr/google\.de/, 'right name';

# Simple request with body
$tx = $ua->get('http://mojolicio.us' => 'Hi there!');
is $tx->req->method, 'GET', 'right method';
is $tx->req->url, 'http://mojolicio.us', 'right url';
is $tx->req->headers->content_length, 9, 'right content length';
is $tx->req->body, 'Hi there!', 'right content';
is $tx->res->code, 200, 'right status';
# Fresh user agent again
$ua = Mojo::UserAgent->new;

# Simple keep alive form POST
$tx = $ua->post_form(
Expand Down

0 comments on commit 3578ae6

Please sign in to comment.