mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
reduce hash lookups and disconnect normalize_port from the options hash
This commit is contained in:
parent
eec571f992
commit
a6f30bea06
1 changed files with 9 additions and 9 deletions
|
@ -81,16 +81,16 @@ module ActionDispatch
|
|||
|
||||
options[:protocol] = normalize_protocol(options)
|
||||
options[:host] = normalize_host(options)
|
||||
options[:port] = normalize_port(options)
|
||||
|
||||
result = options[:protocol]
|
||||
result = options[:protocol].dup
|
||||
|
||||
if options[:user] && options[:password]
|
||||
result << "#{Rack::Utils.escape(options[:user])}:#{Rack::Utils.escape(options[:password])}@"
|
||||
end
|
||||
|
||||
result << options[:host]
|
||||
result << ":#{options[:port]}" if options[:port]
|
||||
port = normalize_port(options[:port], options[:protocol])
|
||||
result << ":#{port}" if port
|
||||
|
||||
result
|
||||
end
|
||||
|
@ -132,16 +132,16 @@ module ActionDispatch
|
|||
host
|
||||
end
|
||||
|
||||
def normalize_port(options)
|
||||
return nil if options[:port].nil? || options[:port] == false
|
||||
def normalize_port(port, protocol)
|
||||
return nil if port.nil? || port == false
|
||||
|
||||
case options[:protocol]
|
||||
case protocol
|
||||
when "//"
|
||||
options[:port]
|
||||
port
|
||||
when "https://"
|
||||
options[:port].to_i == 443 ? nil : options[:port]
|
||||
port.to_i == 443 ? nil : port
|
||||
else
|
||||
options[:port].to_i == 80 ? nil : options[:port]
|
||||
port.to_i == 80 ? nil : port
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue