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
This commit is contained in:
David Heinemeier Hansson 2004-12-18 18:01:28 +00:00
parent a7532f9d5f
commit 61960e7b37
4 changed files with 34 additions and 7 deletions

View File

@ -1,5 +1,7 @@
*SVN*
* Added Request#port_string to get something like ":8080" back on 8080 and "" on 80 (or 443 with https).
* Added Request#domain (returns string) and Request#subdomains (returns array).
* Added POST support for the breakpoint retries, so form processing that raises an exception can be retried with the original request [Florian Gross]

View File

@ -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
#--

View File

@ -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

View File

@ -23,4 +23,26 @@ class RequestTest < Test::Unit::TestCase
@request.host = "dev.www.rubyonrails.co.uk"
assert_equal %w( dev www ), @request.subdomains(2)
end
def test_port_string
@request.port = 80
assert_equal "", @request.port_string
@request.port = 8080
assert_equal ":8080", @request.port_string
end
def test_host_with_port
@request.env['HTTP_HOST'] = "rubyonrails.org:8080"
assert_equal "rubyonrails.org:8080", @request.host_with_port
@request.env['HTTP_HOST'] = nil
@request.host = "rubyonrails.org"
@request.port = 80
assert_equal "rubyonrails.org", @request.host_with_port
@request.host = "rubyonrails.org"
@request.port = 81
assert_equal "rubyonrails.org:81", @request.host_with_port
end
end