Subject: | X-Died responses should not be considered as successful |
If an LWP request fails with an internal exception, then the pseudo header X-Died is set, but the request is still consindered as "successful". See the attached test script.
Also, the documentation for the X-Died header is not complete. It's just mentioned for the :content_cb option of ->get, but apparently may also happen for :content_file. It's also not mentioned for ->request(HTTP::Response->new(...), $dest_file).
Subject: | x-died.t |
#!/usr/bin/perl -w
use strict;
use Cwd 'realpath';
use File::Temp 'tempfile';
use HTTP::Request;
use LWP::UserAgent;
use Test::More 'no_plan';
my($tmpfh,$tmpfile) = tempfile(UNLINK => 1);
close $tmpfh;
chmod 0400, $tmpfile or die $!;
my $res = LWP::UserAgent->new->get('file://' . realpath($0), ':content_file' => $tmpfile);
# or: my $res = LWP::UserAgent->new->request(HTTP::Request->new('GET', 'file://' . realpath($0)), $tmpfile);
ok $res->header('X-Died'), 'X-Died header seen';
ok $res->is_error, 'response is an error';
ok !$res->is_success, 'response is not successful';
__END__