Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Emit a warning if HTTP status code implies success but X-Died header has been set #25

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
language: perl
perl:
- "5.26"
- "5.24"
- "5.22"
- "5.20"
Expand Down
4 changes: 4 additions & 0 deletions cpanfile
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,14 @@ requires "strict" => "0";
requires "warnings" => "0";

on 'test' => sub {
requires "Cwd" => "0";
requires "ExtUtils::MakeMaker" => "0";
requires "File::Spec" => "0";
requires "File::Temp" => "0";
requires "PerlIO::encoding" => "0";
requires "Test::More" => "0.88";
requires "Test::Needs" => "0";
requires "Test::Warnings" => "0";
requires "Time::Local" => "0";
requires "Try::Tiny" => "0";
requires "perl" => "5.008001";
Expand Down
14 changes: 13 additions & 1 deletion lib/HTTP/Response.pm
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,19 @@ sub dump


sub is_info { HTTP::Status::is_info (shift->{'_rc'}); }
sub is_success { HTTP::Status::is_success (shift->{'_rc'}); }
sub is_success {
my $self = shift;
if ( HTTP::Status::is_success( $self->{'_rc'} )
&& $self->header( 'X-Died' ) )
{
my $warning = <<'EOF';
The HTTP status code implies success, but the X-Died header has been set
internally. Something has gone wrong: '
EOF
warn $warning . $self->header('X-Died');
}
return HTTP::Status::is_success( $self->{'_rc'} );
}
sub is_redirect { HTTP::Status::is_redirect (shift->{'_rc'}); }
sub is_error { HTTP::Status::is_error (shift->{'_rc'}); }
sub is_client_error { HTTP::Status::is_client_error (shift->{'_rc'}); }
Expand Down
20 changes: 20 additions & 0 deletions t/x-died.t
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#!/usr/bin/perl -w

use strict;
use warnings;

use Cwd 'realpath';
use File::Temp 'tempfile';
use Test::Needs { 'LWP::UserAgent' => 6.05 };
use Test::More;
use Test::Warnings ':all';

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);
ok $res->header('X-Died'), 'X-Died header seen';
like(warning { $res->is_success }, qr{X\-Died}, 'warning about X-Died header seen.');

done_testing();