| Server IP : 45.40.142.9 / Your IP : 216.73.216.250 Web Server : Apache System : Linux s45-40-142-9.secureserver.net 2.6.32-754.35.1.el6.x86_64 #1 SMP Sat Nov 7 12:42:14 UTC 2020 x86_64 User : bayspec ( 506) PHP Version : 5.6.40 Disable Function : NONE MySQL : ON | cURL : ON | WGET : ON | Perl : ON | Python : ON | Sudo : ON | Pkexec : ON Directory : /.cpanm/latest-build/HTTP-Tiny-0.070/t/ |
Upload File : |
#!perl
use strict;
use warnings;
use Test::More;
use lib 't';
use Util qw[tmpfile monkey_patch set_socket_source];
use HTTP::Tiny;
BEGIN { monkey_patch() }
my %usage = (
'get' => q/Usage: $http->get(URL, [HASHREF])/,
'mirror' => q/Usage: $http->mirror(URL, FILE, [HASHREF])/,
'request' => q/Usage: $http->request(METHOD, URL, [HASHREF])/,
);
my @cases = (
['get'],
['get','http://www.example.com/','extra'],
['get','http://www.example.com/','extra', 'extra'],
['mirror'],
['mirror','http://www.example.com/',],
['mirror','http://www.example.com/','extra', 'extra'],
['mirror','http://www.example.com/','extra', 'extra', 'extra'],
['request'],
['request','GET'],
['request','GET','http://www.example.com/','extra'],
['request','GET','http://www.example.com/','extra', 'extra'],
);
my $res_fh = tmpfile();
my $req_fh = tmpfile();
my $http = HTTP::Tiny->new;
set_socket_source($req_fh, $res_fh);
for my $c ( @cases ) {
my ($method, @args) = @$c;
eval {$http->$method(@args)};
my $err = $@;
like ($err, qr/\Q$usage{$method}\E/, join("|",@$c) );
}
my $res = eval{ $http->get("http://www.example.com/", { headers => { host => "www.example2.com" } } ) };
is( $res->{status}, 599, "Providing a Host header errors with 599" );
like( $res->{content}, qr/'Host' header/, "Providing a Host header gives right error message" );
done_testing;