diff options
author | Eileen M. Uchitelle <eileencodes@gmail.com> | 2016-05-14 11:38:59 -0400 |
---|---|---|
committer | Eileen M. Uchitelle <eileencodes@gmail.com> | 2016-05-14 11:38:59 -0400 |
commit | c83e6847c00d8747cffa6d8c8273ed134833d138 (patch) | |
tree | 0b7aee9c3c8c4c6078bb92a09424d6065e8de285 | |
parent | 83ecf3fe56f0c4b89cc5f2c5bdab6e0e7d26b7a1 (diff) | |
parent | 775703e1f9b99500ecc362fd0eef5212b3580619 (diff) | |
download | rails-c83e6847c00d8747cffa6d8c8273ed134833d138.tar.gz rails-c83e6847c00d8747cffa6d8c8273ed134833d138.tar.bz2 rails-c83e6847c00d8747cffa6d8c8273ed134833d138.zip |
Merge pull request #24992 from tomkadwill/test_and_comment_server_port_rebased
Document and test ActionDispatch server_port
-rw-r--r-- | actionpack/lib/action_dispatch/http/url.rb | 11 | ||||
-rw-r--r-- | actionpack/test/dispatch/request_test.rb | 11 |
2 files changed, 22 insertions, 0 deletions
diff --git a/actionpack/lib/action_dispatch/http/url.rb b/actionpack/lib/action_dispatch/http/url.rb index b7a6aeee7d..7a1350a46d 100644 --- a/actionpack/lib/action_dispatch/http/url.rb +++ b/actionpack/lib/action_dispatch/http/url.rb @@ -354,6 +354,17 @@ module ActionDispatch 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 diff --git a/actionpack/test/dispatch/request_test.rb b/actionpack/test/dispatch/request_test.rb index 781f852633..8a5d85ab84 100644 --- a/actionpack/test/dispatch/request_test.rb +++ b/actionpack/test/dispatch/request_test.rb @@ -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 |