Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix_headers() now initializes Host header when needed #2234

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading