| 1 | package HTTP::Tiny::Paranoid; | ||
| 2 | $HTTP::Tiny::Paranoid::VERSION = '0.04'; | ||
| 3 | use strict; | ||
| 4 | use warnings; | ||
| 5 | |||
| 6 | # ABSTRACT: A safer HTTP::Tiny | ||
| 7 | |||
| 8 | use parent 'HTTP::Tiny'; | ||
| 9 | use Net::DNS::Paranoid; | ||
| 10 | use Class::Method::Modifiers; | ||
| 11 | |||
| 12 | my $dns = Net::DNS::Paranoid->new; | ||
| 13 | |||
| 14 | sub blocked_hosts { shift; $dns->blocked_hosts(@_) } | ||
| 15 | sub whitelisted_hosts { shift; $dns->whitelisted_hosts(@_) } | ||
| 16 | |||
| 17 | around _open_handle => sub { | ||
| 18 | my $next = shift; | ||
| 19 | my $self = shift; | ||
| 20 | |||
| 21 | my ($req, $scheme, $host, $port) = @_; | ||
| 22 | my ($ips, $error) = $dns->resolve($host); | ||
| 23 | die "$host: $error\n" if defined $error; | ||
| 24 | die "$host: no IP address found\n" unless @$ips; | ||
| 25 | |||
| 26 | $self->$next($req, $scheme, $ips->[0], $port); | ||
| 27 | }; | ||
| 28 | |||
| 29 | 1; | ||
| 30 | __END__ |