From d691a9629370abb103bbb6ba6d7eb26b65e122f7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?V=C3=ADt=20Str=C3=A1dal?= Date: Wed, 17 Feb 2021 13:14:45 +0100 Subject: [PATCH] #62 fix warnings during HTTP::Config->match --- Changes | 1 + lib/HTTP/Config.pm | 8 ++++++-- t/http-config.t | 11 ++++++++++- 3 files changed, 17 insertions(+), 3 deletions(-) diff --git a/Changes b/Changes index f266f9fe..b307aaf0 100644 --- a/Changes +++ b/Changes @@ -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 diff --git a/lib/HTTP/Config.pm b/lib/HTTP/Config.pm index e2bd649d..0101b528 100644 --- a/lib/HTTP/Config.pm +++ b/lib/HTTP/Config.pm @@ -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 { diff --git a/t/http-config.t b/t/http-config.t index c0b8825d..0e064674 100644 --- a/t/http-config.t +++ b/t/http-config.t @@ -2,7 +2,7 @@ use strict; use warnings; use Test::More; -plan tests => 28; +plan tests => 30; use HTTP::Config; @@ -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)); + }