module ActionDispatch::Http::URL

def server_port

req.server_port # => 8080
req = ActionDispatch::Request.new 'SERVER_PORT' => '8080'

req.server_port # => 80
req = ActionDispatch::Request.new 'SERVER_PORT' => '80'

Returns the requested port, such as 8080, based on SERVER_PORT
def server_port
  get_header("SERVER_PORT").to_i
end