File: hijkurl

package info (click to toggle)
libhijk-perl 0.28-2
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 260 kB
  • sloc: perl: 1,372; makefile: 8
file content (44 lines) | stat: -rw-r--r-- 968 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
#!/usr/bin/env perl
use strict;
use warnings;
use Getopt::Long;
use Hijk;
use URI;

my ($method, $output_file, $header, $body) = ("GET", "-", "");
my $timeout = 60;
my $dump_header;
GetOptions(
    "method|X=s" => \$method,
    "H=s",       => \$header,
    'd=s',       => \$body,
    "output|o=s" => \$output_file,
    "timeout=s" => \$timeout,
    "D|dump-header=s" => \$dump_header,
);
$method = uc($method);

my $uri_string = shift(@ARGV) or die "$0 <url>";

my $uri = URI->new($uri_string);

my $res = Hijk::request {
    method => $method,
    host => $uri->host,
    port => $uri->port || 80,
    timeout => $timeout*1000,
    path => $uri->path,
    query_string => $uri->query,
    $header ? ( head => [split /: /, $header, 2] ) : (),
    $body   ? ( body => $body                    ) : (),
    parse_chunked => 1,
};

if ($dump_header) {
    for (keys %{$res->{head}}) {
        print "$_: $res->{head}{$_}\n";
    }
    print "\n";
}

print $res->{body};