Skip to content

Commit

Permalink
fix_headers() now initializes Host header when needed
Browse files Browse the repository at this point in the history
RFC9112 §3.2-5 says that Host is mandatory, but can be an empty value.
resolves issue #2232.
  • Loading branch information
karenetheridge committed Feb 24, 2025
1 parent 2376b90 commit b872ef8
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/Mojo/Message/Request.pm
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ sub fix_headers {

# Host
my $url = $self->url;
$headers->host($url->host_port) unless $headers->host;
$headers->host($url->host_port // '') unless defined $headers->host;

# Basic authentication
if ((my $info = $url->userinfo) && !$headers->authorization) {
Expand Down
5 changes: 5 additions & 0 deletions t/mojo/request.t
Original file line number Diff line number Diff line change
Expand Up @@ -475,6 +475,11 @@ subtest 'Parse full HTTP 1.0 request (no scheme and empty elements in path)' =>
is $req->url, '//foo/bar//baz.html?foo=13', 'right URL';
is $req->headers->content_type, 'text/plain', 'right "Content-Type" value';
is $req->headers->content_length, 27, 'right "Content-Length" value';
is $req->headers->host, undef, '"Host" value is not defined';

$req->fix_headers;
is $req->url->host, undef, 'still no url host';
is $req->headers->host, '', '"Host" value is fixed';
};

subtest 'Parse full HTTP 1.0 request (behind reverse proxy)' => sub {
Expand Down

0 comments on commit b872ef8

Please sign in to comment.