| 1 |
#!/usr/bin/env perl |
| 2 |
use strict; |
| 3 |
use warnings; |
| 4 |
use Getopt::Long; |
| 5 |
use Hijk; |
| 6 |
use URI; |
| 7 |
|
| 8 |
my ($method, $output_file, $header, $body) = ("GET", "-", ""); |
| 9 |
my $timeout = 60; |
| 10 |
my $dump_header; |
| 11 |
GetOptions( |
| 12 |
"method|X=s" => \$method, |
| 13 |
"H=s", => \$header, |
| 14 |
'd=s', => \$body, |
| 15 |
"output|o=s" => \$output_file, |
| 16 |
"timeout=s" => \$timeout, |
| 17 |
"D|dump-header=s" => \$dump_header, |
| 18 |
); |
| 19 |
$method = uc($method); |
| 20 |
|
| 21 |
my $uri_string = shift(@ARGV) or die "$0 <url>"; |
| 22 |
|
| 23 |
my $uri = URI->new($uri_string); |
| 24 |
|
| 25 |
my $res = Hijk::request { |
| 26 |
method => $method, |
| 27 |
host => $uri->host, |
| 28 |
port => $uri->port || 80, |
| 29 |
timeout => $timeout*1000, |
| 30 |
path => $uri->path, |
| 31 |
query_string => $uri->query, |
| 32 |
$header ? ( head => [split /: /, $header, 2] ) : (), |
| 33 |
$body ? ( body => $body ) : (), |
| 34 |
parse_chunked => 1, |
| 35 |
}; |
| 36 |
|
| 37 |
if ($dump_header) { |
| 38 |
for (keys %{$res->{head}}) { |
| 39 |
print "$_: $res->{head}{$_}\n"; |
| 40 |
} |
| 41 |
print "\n"; |
| 42 |
} |
| 43 |
|
| 44 |
print $res->{body}; |