package Catalyst::Request;
-use IO::Socket qw[AF_INET inet_aton];
+use Socket qw( getaddrinfo getnameinfo AI_NUMERICHOST NI_DGRAM NIx_NOSERV );
use Carp;
use utf8;
use URI::http;
# Check for definedness as you could read '0'
while ( defined ( my $chunk = $self->read() ) ) {
$self->prepare_body_chunk($chunk);
- $stream_buffer->print($chunk) if $stream_buffer;
+ next unless $stream_buffer;
+
+ $stream_buffer->print($chunk)
+ || die sprintf "Failed to write %d bytes to psgi.input file: $!", length( $chunk );
}
# Ok, we read the body. Lets play nice for any PSGI app down the pipe
lazy => 1,
default => sub {
my ($self) = @_;
- gethostbyaddr( inet_aton( $self->address ), AF_INET ) || $self->address
+ my ( $err, $sockaddr ) = getaddrinfo(
+ $self->address,
+ # no service
+ '',
+ { flags => AI_NUMERICHOST }
+ );
+ if ( $err ) {
+ $self->_log->warn("resolve of hostname failed: $err");
+ return $self->address;
+ }
+ ( $err, my $hostname ) = getnameinfo(
+ $sockaddr->{addr},
+ # we are only interested in the hostname, not the servicename
+ NI_DGRAM|NIx_NOSERV
+ );
+ if ( $err ) {
+ $self->_log->warn("resolve of hostname failed: $err");
+ return $self->address;
+ }
+ return $hostname;
},
);