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
from
File filter...
Filter file types
Jump to file or symbol
Failed to load files and symbols.
+38 −1
Diff settings

Always

Just for now

Copy path View file
@@ -1,5 +1,6 @@
language: perl
perl:
- "5.26"
- "5.24"
- "5.22"
- "5.20"
Copy path View file
@@ -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";
Copy path View file
@@ -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'}); }
Copy path View file
@@ -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();
ProTip! Use n and p to navigate between commits in a pull request.