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 17, 2021
1 parent 02e11bc commit 342a1b5
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 5 deletions.
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
9 changes: 6 additions & 3 deletions t/http-config.t
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@ use strict;
use warnings;

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

plan tests => 29;

use HTTP::Config;

Expand Down Expand Up @@ -42,6 +44,7 @@ $conf->add_item("not secure", m_secure => 0);
$conf->add_item("slash", m_host_port => "www.example.com:80", m_path_prefix => "/");
$conf->add_item("u:p", m_host_port => "www.example.com:80", m_path_prefix => "/foo");
$conf->add_item("success", m_code => "2xx");
$conf->add_item("text", m_header__content_type => "text/plain");
is($conf->find(m_domain => ".com")->{item}, '.com');
my @found = $conf->find(m_domain => ".com");
is($#found, 0);
Expand All @@ -66,11 +69,11 @@ $response->content_type("text/plain");
$response->content("Hello, world!\n");
$response->request($request);

is(j($conf->matching_items($response)), ".com|success|GET|secure|always");
is(j($conf->matching_items($response)), ".com|success|GET|secure|text|always");

$conf->remove_items(m_secure => 1);
$conf->remove_items(m_domain => ".com");
is(j($conf->matching_items($response)), "success|GET|always");
is(j($conf->matching_items($response)), "success|GET|text|always");

$conf->remove_items; # start fresh
is(j($conf->matching_items($response)), "");
Expand Down

0 comments on commit 342a1b5

Please sign in to comment.