From 9cacfa256a9f9c3798b0d8b67e413217a32ec90c Mon Sep 17 00:00:00 2001 From: Jesse Luehrs Date: Thu, 27 Sep 2012 11:09:11 -0500 Subject: add 'host' method --- lib/Web/Request.pm | 23 +++++++++++++++++++---- 1 file changed, 19 insertions(+), 4 deletions(-) (limited to 'lib') diff --git a/lib/Web/Request.pm b/lib/Web/Request.pm index fa8cf3a..d0d90e0 100644 --- a/lib/Web/Request.pm +++ b/lib/Web/Request.pm @@ -81,10 +81,7 @@ has _base_uri => ( my $env = $self->env; my $scheme = $self->scheme || "http"; - my $server = $env->{HTTP_HOST}; - $server = ($env->{SERVER_NAME} || '') . ':' - . ($env->{SERVER_PORT} || 80) - unless defined $server; + my $server = $self->host; my $path = $self->script_name || '/'; return "${scheme}://${server}${path}"; @@ -431,6 +428,18 @@ sub _new_upload { $self->upload_class->new(@_); } +sub host { + my $self = shift; + + my $env = $self->env; + my $host = $env->{HTTP_HOST}; + $host = ($env->{SERVER_NAME} || '') . ':' + . ($env->{SERVER_PORT} || 80) + unless defined $host; + + return $host; +} + sub path { my $self = shift; @@ -559,6 +568,12 @@ Returns the HTTP method (GET, POST, etc.) used in the current request. Returns the local port that this request was made on. +=method host + +Returns the contents of the HTTP C header. If it doesn't exist, falls +back to recreating the host from the C and C +variables. + =method path Returns the request path for the current request. Unlike C, this -- cgit v1.2.3-54-g00ecf