diff options
author | Aaron Patterson <aaron.patterson@gmail.com> | 2014-06-11 11:48:39 -0700 |
---|---|---|
committer | Aaron Patterson <aaron.patterson@gmail.com> | 2014-06-11 11:48:39 -0700 |
commit | 85ba47e3f16b3cbc3adbfc673727db709cc1ba63 (patch) | |
tree | 489ff29667ac22065d768b58cd3eb06e65657e47 /actionpack/lib/action_dispatch/http | |
parent | ec1caddb7f93a4277a6ab0727b2c41b34cafbfa5 (diff) | |
download | rails-85ba47e3f16b3cbc3adbfc673727db709cc1ba63.tar.gz rails-85ba47e3f16b3cbc3adbfc673727db709cc1ba63.tar.bz2 rails-85ba47e3f16b3cbc3adbfc673727db709cc1ba63.zip |
cache host on the stack so we only look it up once
Diffstat (limited to 'actionpack/lib/action_dispatch/http')
-rw-r--r-- | actionpack/lib/action_dispatch/http/url.rb | 17 |
1 files changed, 9 insertions, 8 deletions
diff --git a/actionpack/lib/action_dispatch/http/url.rb b/actionpack/lib/action_dispatch/http/url.rb index 86915cfc27..6112ab2fd6 100644 --- a/actionpack/lib/action_dispatch/http/url.rb +++ b/actionpack/lib/action_dispatch/http/url.rb @@ -74,14 +74,15 @@ module ActionDispatch def build_host_url(options) protocol = options[:protocol] - if match = options[:host].match(HOST_REGEXP) + host = options[:host] + if match = host.match(HOST_REGEXP) protocol ||= match[1] unless protocol == false - options[:host] = match[2] + host = match[2] options[:port] = match[3] unless options.key?(:port) end protocol = normalize_protocol protocol - options[:host] = normalize_host(options) + host = normalize_host(host, options) result = protocol.dup @@ -89,7 +90,7 @@ module ActionDispatch result << "#{Rack::Utils.escape(options[:user])}:#{Rack::Utils.escape(options[:password])}@" end - result << options[:host] + result << host normalize_port(options[:port], protocol) { |port| result << ":#{port}" } @@ -118,19 +119,19 @@ module ActionDispatch end end - def normalize_host(options) - return options[:host] if !named_host?(options[:host]) || same_host?(options) + def normalize_host(_host, options) + return _host if !named_host?(_host) || same_host?(options) tld_length = options[:tld_length] || @@tld_length host = "" if options[:subdomain] == true || !options.key?(:subdomain) - host << extract_subdomain(options[:host], tld_length).to_param + host << extract_subdomain(_host, tld_length).to_param elsif options[:subdomain].present? host << options[:subdomain].to_param end host << "." unless host.empty? - host << (options[:domain] || extract_domain(options[:host], tld_length)) + host << (options[:domain] || extract_domain(_host, tld_length)) host end |