Skip to content

Commit

Permalink
Set Host: header and HTTP_HOST based on $request->uri. Fixes plack#177
Browse files Browse the repository at this point in the history
  • Loading branch information
miyagawa committed Mar 31, 2012
1 parent b2f3ffb commit e91f4c6
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 0 deletions.
4 changes: 4 additions & 0 deletions lib/HTTP/Message/PSGI.pm
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,10 @@ sub req_to_psgi {
$env->{PATH_INFO} =~ s/^\/+/\//;
}

if (!$env->{HTTP_HOST} && $req->uri->can('host')) {
$env->{HTTP_HOST} = $req->uri->host;
}

return $env;
}

Expand Down
27 changes: 27 additions & 0 deletions t/HTTP-Message-PSGI/host.t
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
use strict;
use warnings;
use Test::More;
use HTTP::Message::PSGI qw(req_to_psgi);
use HTTP::Request;

{
my $req = HTTP::Request->new(GET => "http://example.com/");
my $env = req_to_psgi $req;

is $env->{HTTP_HOST}, 'example.com';
is $env->{PATH_INFO}, '/';
}

{
my $req = HTTP::Request->new(GET => "/");
$req->header('Host' => "perl.com");
my $env = req_to_psgi $req;

is $env->{HTTP_HOST}, 'perl.com';
is $env->{PATH_INFO}, '/';
}

done_testing;



0 comments on commit e91f4c6

Please sign in to comment.