Permalink
Browse files

Merge pull request #24992 from tomkadwill/test_and_comment_server_por…

…t_rebased

Document and test ActionDispatch server_port
  • Loading branch information...
eileencodes committed May 14, 2016
2 parents 83ecf3f + 775703e commit c83e6847c00d8747cffa6d8c8273ed134833d138
Showing with 22 additions and 0 deletions.
  1. +11 −0 actionpack/lib/action_dispatch/http/url.rb
  2. +11 −0 actionpack/test/dispatch/request_test.rb
@@ -354,6 +354,17 @@ def port_string
standard_port? ? '' : ":#{port}"
end
# Returns the requested port, such as 8080, based on SERVER_PORT
#
# class Request < Rack::Request
# include ActionDispatch::Http::URL
# end
#
# req = Request.new 'SERVER_PORT' => '80'
# req.server_port # => 80
#
# req = Request.new 'SERVER_PORT' => '8080'
# req.server_port # => 8080
def server_port
get_header('SERVER_PORT').to_i
end
@@ -358,6 +358,17 @@ class RequestPort < BaseRequestTest
request = stub_request 'HTTP_HOST' => 'www.example.org:8080'
assert_equal ':8080', request.port_string
end
test "server port" do
request = stub_request 'SERVER_PORT' => '8080'
assert_equal 8080, request.server_port
request = stub_request 'SERVER_PORT' => '80'
assert_equal 80, request.server_port
request = stub_request 'SERVER_PORT' => ''
assert_equal 0, request.server_port
end
end
class RequestPath < BaseRequestTest

0 comments on commit c83e684

Please sign in to comment.