Skip to content

Commit

Permalink
#62 fix warnings during HTTP::Config->match
Browse files Browse the repository at this point in the history
  • Loading branch information
vitstradal authored and oalders committed Feb 19, 2021
1 parent 02e11bc commit 9b9d67d
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 3 deletions.
1 change: 1 addition & 0 deletions Changes
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
Revision history for HTTP-Message

{{$NEXT}}
- fix warnings during HTTP::Config->match #62 (GH#152) (Viťas Strádal)

6.27 2021-01-05 03:02:01Z
- Clean up backcompat code (GH#148) (Dan Book)
Expand Down
8 changes: 6 additions & 2 deletions lib/HTTP/Config.pm
Original file line number Diff line number Diff line change
Expand Up @@ -155,8 +155,12 @@ my %MATCH = (
m_header__ => sub {
my($v, $k, $uri, $request, $response) = @_;
return unless $request;
return 1 if $request->header($k) eq $v;
return 1 if $response && $response->header($k) eq $v;
my $req_header = $request->header($k);
return 1 if defined($req_header) && $req_header eq $v;
if ($response) {
my $res_header = $response->header($k);
return 1 if defined($res_header) && $res_header eq $v;
}
return 0;
},
m_response_attr__ => sub {
Expand Down
11 changes: 10 additions & 1 deletion t/http-config.t
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use strict;
use warnings;

use Test::More;
plan tests => 28;
plan tests => 30;

use HTTP::Config;

Expand Down Expand Up @@ -103,4 +103,13 @@ is(j($conf->matching_items($response)), "HTML|html|text|any");
ok(($conf->empty), 'found and removed the config entry');
is(scalar(@warnings), 0, 'no warnings')
or diag('got warnings: ', explain(\@warnings));

@warnings = ();
$conf->add_item("bond", m_header__user_agent => 'james/0.0.7');
my $request2 = HTTP::Request->new(HEAD => "http://www.example.com/foo/bar");
is(j($conf->matching_items($request2)), '');

is(scalar(@warnings), 0, 'no warnings')
or diag('got warnings: ', explain(\@warnings));

}

0 comments on commit 9b9d67d

Please sign in to comment.