From: Andy Grundman Date: Fri, 14 Sep 2007 17:10:31 +0000 (+0000) Subject: Fixed bug where req->base and req->uri would include ':443' when in SSL mode X-Git-Tag: 5.7099_04~133 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?p=catagits%2FCatalyst-Runtime.git;a=commitdiff_plain;h=de19de2e6f40d9f8986df5e4f37dc8084a7c83ee;hp=8af92bd80996775f80e5804483cc44b136aa1933 Fixed bug where req->base and req->uri would include ':443' when in SSL mode --- diff --git a/Changes b/Changes index 5af8216..abb5069 100644 --- a/Changes +++ b/Changes @@ -11,6 +11,8 @@ 'Resource temporarily unavailable'. - Fixed bug where %2b in query parameter is doubly decoded to ' ', instead of '+' (Gavin Henry, Tatsuhiko Miyagawa) + - Fixed bug where req->base and req->uri would include a port number when running + in SSL mode. 5.7010 2007-08-22 07:41:00 - Resource forks in 5.7009 diff --git a/lib/Catalyst/Engine/CGI.pm b/lib/Catalyst/Engine/CGI.pm index 8ceaef1..4b699d3 100644 --- a/lib/Catalyst/Engine/CGI.pm +++ b/lib/Catalyst/Engine/CGI.pm @@ -143,10 +143,10 @@ sub prepare_path { # Using URI directly is way too slow, so we construct the URLs manually my $uri_class = "URI::$scheme"; - # HTTP_HOST will include the port even if it's 80 - $host =~ s/:80$//; + # HTTP_HOST will include the port even if it's 80/443 + $host =~ s/:(?:80|443)$//; - if ( $port != 80 && $host !~ /:/ ) { + if ( $port !~ /^(?:80|443)$/ && $host !~ /:/ ) { $host .= ":$port"; } diff --git a/lib/Catalyst/Request.pm b/lib/Catalyst/Request.pm index 763c3ef..e370983 100644 --- a/lib/Catalyst/Request.pm +++ b/lib/Catalyst/Request.pm @@ -6,6 +6,8 @@ use base 'Class::Accessor::Fast'; use IO::Socket qw[AF_INET inet_aton]; use Carp; use utf8; +use URI::http; +use URI::https; use URI::QueryParam; __PACKAGE__->mk_accessors( diff --git a/t/live_component_controller_action_chained.t b/t/live_component_controller_action_chained.t index 411542e..a4879f6 100644 --- a/t/live_component_controller_action_chained.t +++ b/t/live_component_controller_action_chained.t @@ -699,7 +699,7 @@ sub run_tests { 'http://localhost/action/chained/to_root' ), 'uri_for with chained root action as arg' ); like( $response->content, - qr(URI:http://[^/]+/), + qr(URI:https?://[^/]+/), 'Correct URI generated' ); } diff --git a/t/live_engine_request_headers.t b/t/live_engine_request_headers.t index fc32874..33c57f9 100644 --- a/t/live_engine_request_headers.t +++ b/t/live_engine_request_headers.t @@ -12,7 +12,6 @@ use Catalyst::Test 'TestApp'; use Catalyst::Request; use HTTP::Headers; use HTTP::Request::Common; -use URI; { my $creq; diff --git a/t/live_engine_request_parameters.t b/t/live_engine_request_parameters.t index 1f1091f..d93437d 100644 --- a/t/live_engine_request_parameters.t +++ b/t/live_engine_request_parameters.t @@ -12,7 +12,6 @@ use Catalyst::Test 'TestApp'; use Catalyst::Request; use HTTP::Headers; use HTTP::Request::Common; -use URI; { my $creq; diff --git a/t/live_engine_request_uri.t b/t/live_engine_request_uri.t index b5fc240..a957b7e 100644 --- a/t/live_engine_request_uri.t +++ b/t/live_engine_request_uri.t @@ -6,7 +6,7 @@ use warnings; use FindBin; use lib "$FindBin::Bin/lib"; -use Test::More tests => 44; +use Test::More tests => 49; use Catalyst::Test 'TestApp'; use Catalyst::Request; @@ -37,6 +37,21 @@ my $creq; is( $creq->base . $creq->path, $creq->uri, 'Base + Path ok' ); } +# test base is correct for HTTPS URLs +SKIP: +{ + if ( $ENV{CATALYST_SERVER} ) { + skip 'Using remote server', 5; + } + + local $ENV{HTTPS} = 'on'; + ok( my $response = request('https://localhost/engine/request/uri'), 'HTTPS Request' ); + ok( $response->is_success, 'Response Successful 2xx' ); + ok( eval '$creq = ' . $response->content, 'Unserialize Catalyst::Request' ); + is( $creq->base, 'https://localhost/', 'HTTPS base ok' ); + is( $creq->uri, 'https://localhost/engine/request/uri', 'HTTPS uri ok' ); +} + # test that we can use semi-colons as separators { my $parameters = { @@ -88,7 +103,7 @@ my $creq; { ok( my $response = request('http://localhost/engine/request/uri/uri_with_object'), 'Request' ); ok( $response->is_success, 'Response Successful 2xx' ); - like( $response->header( 'X-Catalyst-Param-a' ), qr(http://localhost[^/]*/), 'param "a" ok' ); + like( $response->header( 'X-Catalyst-Param-a' ), qr(https?://localhost[^/]*/), 'param "a" ok' ); } # test that uri_with is utf8 safe