From: Ken-ichi Mito Date: Thu, 6 Mar 2014 06:40:19 +0000 (+0900) Subject: use LWP::UserAgent instead of LWP::Simple X-Git-Url: http://lab.mitty.jp/git/?a=commitdiff_plain;h=8c96802f20c76f2a62c681ae640598f5cd5edd1e;p=lab.git use LWP::UserAgent instead of LWP::Simple * LWP::Simple does not support verify_hostname option * {verify_hostname => 0} enables access to https://192.168... --- diff --git a/misc/httpbench.pl b/misc/httpbench.pl index 6f2e04d..ca04570 100755 --- a/misc/httpbench.pl +++ b/misc/httpbench.pl @@ -6,7 +6,7 @@ use utf8; use Getopt::Long qw(:config posix_default no_ignore_case gnu_compat); use Parallel::ForkManager; -use LWP::Simple; +use LWP::UserAgent; use Time::HiRes qw(sleep gettimeofday); usage() if (@ARGV == 0); @@ -33,7 +33,9 @@ warn "$num urls with $concurrency clients, $loops loops\n"; warn "Total: ", $num * $concurrency * $loops, " requests\n"; warn "wait for $wait second between requests\n" if ($wait); - +my $ua = LWP::UserAgent->new( + ssl_opts => { verify_hostname => 0 }, +); my $transfer = 0; my $pm = Parallel::ForkManager->new($concurrency); $pm->run_on_finish( @@ -57,9 +59,12 @@ my ($startsec, $startmicro) = gettimeofday(); for (my $i = 0; $i < $loops; $i++) { print STDERR "processing $i/$loops loop\r"; foreach my $url (@urls) { - my $res = get($url) or print STDERR "\nfail: $url"; - if ($res) { - $transfer += length($res); + my $res = $ua->get($url); + if ($res->is_success) { + $transfer += length($res->content); + } + else { + print STDERR "\nfail: $url"; } sleep($wait); }