diff options
Diffstat (limited to 'actionpack/lib')
-rw-r--r-- | actionpack/lib/action_controller/cgi_process.rb | 10 | ||||
-rwxr-xr-x | actionpack/lib/action_controller/request.rb | 12 |
2 files changed, 19 insertions, 3 deletions
diff --git a/actionpack/lib/action_controller/cgi_process.rb b/actionpack/lib/action_controller/cgi_process.rb index 4413a29791..7f05e21cb8 100644 --- a/actionpack/lib/action_controller/cgi_process.rb +++ b/actionpack/lib/action_controller/cgi_process.rb @@ -79,7 +79,15 @@ module ActionController #:nodoc: end def host - env["HTTP_X_FORWARDED_HOST"] || @cgi.host.to_s.split(":").first || '' + env["HTTP_X_FORWARDED_HOST"] || ($1 if env['HTTP_HOST'] && /^(.*):\d+$/ =~ env['HTTP_HOST']) || @cgi.host.to_s.split(":").first || '' + end + + def port + env["HTTP_X_FORWARDED_HOST"] ? standard_port : (port_from_http_host || super) + end + + def port_from_http_host + $1.to_i if env['HTTP_HOST'] && /:(\d+)$/ =~ env['HTTP_HOST'] end def session diff --git a/actionpack/lib/action_controller/request.rb b/actionpack/lib/action_controller/request.rb index e5dc424476..aace415943 100755 --- a/actionpack/lib/action_controller/request.rb +++ b/actionpack/lib/action_controller/request.rb @@ -174,17 +174,25 @@ module ActionController def port @port_as_int ||= env['SERVER_PORT'].to_i end + + # Returns the standard port number for this request's protocol + def standard_port + case protocol + when 'https://' then 443 + else 80 + end + end # Returns a port suffix like ":8080" if the port number of this request # is not the default HTTP port 80 or HTTPS port 443. def port_string - (protocol == 'http://' && port == 80) || (protocol == 'https://' && port == 443) ? '' : ":#{port}" + (port == standard_port) ? '' : ":#{port}" end # Returns a host:port string for this request, such as example.com or # example.com:8080. def host_with_port - env['HTTP_HOST'] || host + port_string + host + port_string end def path_parameters=(parameters) |