Skip to content

Commit 9b9d67d

Browse files
vitstradaloalders
authored andcommitted
#62 fix warnings during HTTP::Config->match
1 parent 02e11bc commit 9b9d67d

File tree

3 files changed

+17
-3
lines changed

3 files changed

+17
-3
lines changed

Changes

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
Revision history for HTTP-Message
22

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

56
6.27 2021-01-05 03:02:01Z
67
- Clean up backcompat code (GH#148) (Dan Book)

lib/HTTP/Config.pm

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -155,8 +155,12 @@ my %MATCH = (
155155
m_header__ => sub {
156156
my($v, $k, $uri, $request, $response) = @_;
157157
return unless $request;
158-
return 1 if $request->header($k) eq $v;
159-
return 1 if $response && $response->header($k) eq $v;
158+
my $req_header = $request->header($k);
159+
return 1 if defined($req_header) && $req_header eq $v;
160+
if ($response) {
161+
my $res_header = $response->header($k);
162+
return 1 if defined($res_header) && $res_header eq $v;
163+
}
160164
return 0;
161165
},
162166
m_response_attr__ => sub {

t/http-config.t

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ use strict;
22
use warnings;
33

44
use Test::More;
5-
plan tests => 28;
5+
plan tests => 30;
66

77
use HTTP::Config;
88

@@ -103,4 +103,13 @@ is(j($conf->matching_items($response)), "HTML|html|text|any");
103103
ok(($conf->empty), 'found and removed the config entry');
104104
is(scalar(@warnings), 0, 'no warnings')
105105
or diag('got warnings: ', explain(\@warnings));
106+
107+
@warnings = ();
108+
$conf->add_item("bond", m_header__user_agent => 'james/0.0.7');
109+
my $request2 = HTTP::Request->new(HEAD => "http://www.example.com/foo/bar");
110+
is(j($conf->matching_items($request2)), '');
111+
112+
is(scalar(@warnings), 0, 'no warnings')
113+
or diag('got warnings: ', explain(\@warnings));
114+
106115
}

0 commit comments

Comments
 (0)