From 85ba47e3f16b3cbc3adbfc673727db709cc1ba63 Mon Sep 17 00:00:00 2001 From: Aaron Patterson Date: Wed, 11 Jun 2014 11:48:39 -0700 Subject: cache host on the stack so we only look it up once --- actionpack/lib/action_dispatch/http/url.rb | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) (limited to 'actionpack/lib/action_dispatch/http') 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 -- cgit v1.2.3