Skip to content

Commit

Permalink
libwww-perl#62 fix warnings during HTTP::Config->match
Browse files Browse the repository at this point in the history
  • Loading branch information
vitstradal committed Feb 19, 2021
1 parent 2e8842e commit d691a96
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
Expand Up @@ -2,6 +2,7 @@ Revision history for HTTP-Message

{{$NEXT}}
- Clean up backcompat code (GH#148) (Dan Book)
- fix warnings during HTTP::Config->match #62 (GH#152) (Viťas Strádal)

6.26 2020-09-10 02:34:25Z
- Update comment which explains in which RFC 451 is defined (GH#143) (Olaf
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 d691a96

Please sign in to comment.