Skip to content

Commit 6ea9615

Browse files
neilboalders
authored andcommitted
don't consider Content-Location when determining the base URI GH#51
RFC 7231 says: The definition of Content-Location has been changed to no longer affect the base URI for resolving relative URI references, due to poor implementation support and the undesirable effect of potentially breaking relative links in content-negotiated resources. This change was originally suggested by Toby Inkster in 2012.
1 parent 889b8b8 commit 6ea9615

File tree

3 files changed

+11
-3
lines changed

3 files changed

+11
-3
lines changed

Changes

+2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
Revision history for HTTP-Message
22

33
{{$NEXT}}
4+
- We now don't consider the Content-Location header when asked
5+
for the base URI. RFC 7231 says we shouldn't. (GH#51) (Neil Bowers)
46

57
6.40 2022-10-12 15:45:52Z
68
- Fixed two typos in the doc, originally reported by FatherC

lib/HTTP/Response.pm

+8-2
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,6 @@ sub base
8484
my $self = shift;
8585
my $base = (
8686
$self->header('Content-Base'), # used to be HTTP/1.1
87-
$self->header('Content-Location'), # HTTP/1.1
8887
$self->header('Base'), # HTTP/1.0
8988
)[0];
9089
if ($base && $base =~ /^$URI::scheme_re:/o) {
@@ -475,7 +474,7 @@ in HTML documents.
475474
476475
=item 2.
477476
478-
A "Content-Base:" or a "Content-Location:" header in the response.
477+
A "Content-Base:" header in the response.
479478
480479
For backwards compatibility with older HTTP implementations we will
481480
also look for the "Base:" header.
@@ -490,6 +489,13 @@ received some redirect responses first.
490489
491490
If none of these sources provide an absolute URI, undef is returned.
492491
492+
B<Note>: previous versions of HTTP::Response would also consider
493+
a "Content-Location:" header,
494+
as L<RFC 2616|https://www.rfc-editor.org/rfc/rfc2616> said it should be.
495+
But this was never widely implemented by browsers,
496+
and now L<RFC 7231|https://www.rfc-editor.org/rfc/rfc7231>
497+
says it should no longer be considered.
498+
493499
When the LWP protocol modules produce the HTTP::Response object, then any base
494500
URI embedded in the document (step 1) will already have initialized the
495501
"Content-Base:" header. (See L<LWP::UserAgent/parse_head>). This means that

t/response.t

+1-1
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ for ($r->redirects) {
105105

106106
is($r->base, $r->request->uri);
107107
$r->push_header("Content-Location", "/1/A/a");
108-
is($r->base, "http://www.sn.no/1/A/a");
108+
is($r->base, $r->request->uri); # we no longer consider Content-Location
109109
$r->push_header("Content-Base", "/2/;a=/foo/bar");
110110
is($r->base, "http://www.sn.no/2/;a=/foo/bar");
111111
$r->push_header("Content-Base", "/3/");

0 commit comments

Comments
 (0)