1#!/usr/bin/perl
2
3use strict;
4use warnings;
5
6use URI;
7
8use Getopt::Long;
9use IO::Async::Loop;
10use Net::Async::HTTP;
11
12my $FAMILY;
13GetOptions(
14   'local-host=s' => \my $LOCAL_HOST,
15   'local-port=i' => \my $LOCAL_PORT,
16   'timeout=f'    => \my $TIMEOUT,
17   'ipv4|4'       => sub { $FAMILY = "inet" },
18   'ipv6|6'       => sub { $FAMILY = "inet6" },
19) or exit 1;
20
21my $loop = IO::Async::Loop->new;
22
23my $ua = Net::Async::HTTP->new(
24   local_host => $LOCAL_HOST,
25   local_port => $LOCAL_PORT,
26   family     => $FAMILY,
27   decode_content => 1,
28);
29$loop->add( $ua );
30
31$ua->configure( timeout => $TIMEOUT ) if defined $TIMEOUT;
32
33$ua->GET( $ARGV[0] )
34   ->on_done( sub {
35      my ( $response ) = @_;
36
37      print $response->as_string;
38   } )
39   ->on_fail( sub {
40      my ( $message ) = @_;
41
42      print STDERR "Failed - $message\n";
43   } )->get;
44