Created
May 23, 2013 09:18
-
-
Save xaicron/5633906 to your computer and use it in GitHub Desktop.
Furl で https の接続先を差し替える人
See also: http://blog.livedoor.jp/xaicron/archives/54022720.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
use strict; | |
use warnings; | |
no warnings 'redefine'; | |
use Furl::HTTP; | |
use Data::Dumper; | |
# monkey patch :) | |
*Furl::HTTP::connect_ssl = sub { | |
package Furl::HTTP; | |
my ($self, $host, $port, $timeout_at) = @_; | |
_requires('IO/Socket/SSL.pm', 'SSL'); | |
my $timeout = $timeout_at - time; | |
return (undef, "Cannot create SSL connection: timeout") | |
if $timeout <= 0; | |
my $iaddr = $self->{inet_aton}->($host, $timeout); | |
my $ssl_opts = $self->_ssl_opts; | |
my $sock = IO::Socket::SSL->new( | |
PeerAddr => Socket::inet_ntoa($iaddr), | |
PeerPort => $port, | |
Timeout => $timeout, | |
SSL_verifycn_name => $host, | |
%$ssl_opts, | |
) or return (undef, "Cannot create SSL connection: " . IO::Socket::SSL::errstr()); | |
_set_sockopts($sock); | |
$sock; | |
}; | |
my $HOST_MAP = { | |
'google.co.jp' => 'github.com', | |
}; | |
my $furl = Furl::HTTP->new( | |
inet_aton => sub { | |
my ($addr_str, $timeout) = @_; | |
Socket::inet_aton($HOST_MAP->{$addr_str} || $addr_str); | |
}, | |
ssl_opts => { | |
SSL_verify_mode => 0, | |
}, | |
); | |
print Dumper [ $furl->get('https://google.co.jp/') ]; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment