Skip to content

Commit 44d3fef

Browse files
andrew-grechkinoalders
authored andcommitted
fix issue with HTTP::Request internal cache for canonical url when using URI::URL
1 parent ff54767 commit 44d3fef

File tree

3 files changed

+21
-4
lines changed

3 files changed

+21
-4
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 issue with HTTP::Request internal cache for canonical url when using URI::URL (GH#146) (andrew-grechkin)
45

56
6.28 2021-02-19 16:22:13Z
67
- fix warnings during HTTP::Config->match #62 (GH#152) (Viťas Strádal)

lib/HTTP/Request.pm

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -96,9 +96,9 @@ sub uri_canonical
9696
my $uri = $self->{_uri};
9797

9898
if (defined (my $canon = $self->{_uri_canonical})) {
99-
# early bailout if these are the exact same string; try to use
100-
# the cheapest comparison method possible
101-
return $canon if $$canon eq $$uri;
99+
# early bailout if these are the exact same string;
100+
# rely on stringification of the URI objects
101+
return $canon if $canon eq $uri;
102102
}
103103

104104
# otherwise we need to refresh the memoized value

t/request.t

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ use strict;
55
use warnings;
66

77
use Test::More;
8-
plan tests => 35;
8+
plan tests => 39;
99

1010
use HTTP::Request;
1111
use Try::Tiny qw( catch try );
@@ -104,6 +104,22 @@ is( $r2->header("Accept-Encoding"), $req->header("Accept-Encoding") );
104104
},
105105
'Object without scheme method triggers an exception'
106106
);
107+
108+
# test uri_canonical cache
109+
{
110+
my $url = 'https://localhost/';
111+
my $r = HTTP::Request->new(GET => $url);
112+
is($r->uri_canonical, $url, 'Works when canonical uri not yet cached');
113+
is($r->uri_canonical, $url, 'Works when canonical uri has been cached');
114+
}
115+
116+
{
117+
require URI::URL;
118+
my $url = 'https://localhost/';
119+
my $r = HTTP::Request->new(GET => URI::URL->new($url));
120+
is($r->uri_canonical, $url, 'Works when canonical uri not yet cached with URI::URL');
121+
is($r->uri_canonical, $url, 'Works when canonical uri has been cached with URI::URL');
122+
}
107123
}
108124

109125
eval { $req->uri ({ foo => 'bar'}); };

0 commit comments

Comments
 (0)