Permalink
Browse files

port_string bought back to life as it is part of the public api

Signed-off-by: José Valim <jose.valim@gmail.com>
  • Loading branch information...
1 parent 0687b21 commit e39138478b38d7a5e0a13756b1bdfa8b43226846 @joshk joshk committed with josevalim Nov 24, 2010
Showing with 17 additions and 4 deletions.
  1. +8 −3 actionpack/lib/action_dispatch/http/url.rb
  2. +9 −1 actionpack/test/dispatch/request_test.rb
@@ -52,8 +52,7 @@ def host
# Returns a \host:\port string for this request, such as "example.com" or
# "example.com:8080".
def host_with_port
- opt_port = optional_port ? ":#{optional_port}" : nil
- "#{host}#{opt_port}"
+ "#{host}#{port_string}"
end
# Returns the port number of this request as an integer.
@@ -80,12 +79,18 @@ def standard_port?
port == standard_port
end
- # Returns a \port suffix like "8080" if the \port number of this request
+ # Returns a number \port suffix like 8080 if the \port number of this request
# is not the default HTTP \port 80 or HTTPS \port 443.
def optional_port
standard_port? ? nil : port
end
+ # Returns a string \port suffix, including colon, like ":8080" if the \port
+ # number of this request is not the default HTTP \port 80 or HTTPS \port 443.
+ def port_string
+ standard_port? ? '' : ":#{port}"
+ end
+
def server_port
@env['SERVER_PORT'].to_i
end
@@ -172,6 +172,14 @@ class RequestTest < ActiveSupport::TestCase
assert_equal 8080, request.optional_port
end
+ test "port string" do
+ request = stub_request 'HTTP_HOST' => 'www.example.org:80'
+ assert_equal '', request.port_string
+
+ request = stub_request 'HTTP_HOST' => 'www.example.org:8080'
+ assert_equal ':8080', request.port_string
+ end
+
test "full path" do
request = stub_request 'SCRIPT_NAME' => '', 'PATH_INFO' => '/path/of/some/uri', 'QUERY_STRING' => 'mapped=1'
assert_equal "/path/of/some/uri?mapped=1", request.fullpath
@@ -392,7 +400,7 @@ class RequestTest < ActiveSupport::TestCase
mock_rack_env = { "QUERY_STRING" => "x[y]=1&x[y][][w]=2", "rack.input" => "foo" }
request = nil
begin
- request = stub_request(mock_rack_env)
+ request = stub_request(mock_rack_env)
request.parameters
rescue TypeError => e
# rack will raise a TypeError when parsing this query string

0 comments on commit e391384

Please sign in to comment.