From 61960e7b37767140e9af68bd5373e06dce08492d Mon Sep 17 00:00:00 2001 From: David Heinemeier Hansson Date: Sat, 18 Dec 2004 18:01:28 +0000 Subject: Added Request#port_string to get something like ":8080" back on 8080 and "" on 80 (or 443 with https). git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@214 5ecf4fe2-1ee6-0310-87b1-e25e094e27de --- actionpack/lib/action_controller/request.rb | 13 ++++++------- actionpack/lib/action_controller/test_process.rb | 4 ++++ 2 files changed, 10 insertions(+), 7 deletions(-) (limited to 'actionpack/lib') diff --git a/actionpack/lib/action_controller/request.rb b/actionpack/lib/action_controller/request.rb index e9ab3cad90..d3d65ec0ec 100755 --- a/actionpack/lib/action_controller/request.rb +++ b/actionpack/lib/action_controller/request.rb @@ -84,14 +84,13 @@ module ActionController env["SERVER_PORT"].to_i end + # Returns a string like ":8080" if the port is not 80 or 443 while on https. + def port_string + (protocol == "http://" && port == 80) || (protocol == "https://" && port == 443) ? "" : ":#{port}" + end + def host_with_port - if env['HTTP_HOST'] - env['HTTP_HOST'] - elsif (protocol == "http://" && port == 80) || (protocol == "https://" && port == 443) - host - else - host + ":#{port}" - end + env['HTTP_HOST'] || host + port_string end #-- diff --git a/actionpack/lib/action_controller/test_process.rb b/actionpack/lib/action_controller/test_process.rb index 3590d29cd3..b248626fa4 100644 --- a/actionpack/lib/action_controller/test_process.rb +++ b/actionpack/lib/action_controller/test_process.rb @@ -37,6 +37,10 @@ module ActionController #:nodoc: @cookies.freeze end + def port=(number) + @env["SERVER_PORT"] = number.to_i + end + def action=(action_name) @query_parameters.update({ "action" => action_name }) @parameters = nil -- cgit v1.2.3