Rewrite of enforce_ssl? to generate all condition variants of options from keys_by_type hash.
This commit is contained in:
Родитель
97558dcdad
Коммит
f7fa4851b8
|
@ -85,7 +85,6 @@ module Rack
|
|||
req.host == pattern
|
||||
when :except_hosts
|
||||
req.host != pattern
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -105,23 +104,33 @@ module Rack
|
|||
end
|
||||
|
||||
def enforce_ssl?(req)
|
||||
path_keys = [:only, :except]
|
||||
hosts_keys = [:only_hosts, :except_hosts]
|
||||
if hosts_keys.any? { |option| @options[option] }
|
||||
if enforce_ssl_for?(hosts_keys, req)
|
||||
if path_keys.any? { |option| @options[option] }
|
||||
enforce_ssl_for?(path_keys, req)
|
||||
else
|
||||
true
|
||||
end
|
||||
else
|
||||
false
|
||||
end
|
||||
elsif path_keys.any? { |option| @options[option] }
|
||||
enforce_ssl_for?(path_keys, req)
|
||||
else
|
||||
true
|
||||
enforce = false
|
||||
keys_by_type = {
|
||||
:hosts => [:only_hosts, :except_hosts], :path => [:only, :except],
|
||||
:methods => [:only_methods, :except_methods]
|
||||
}
|
||||
|
||||
if !keys_by_type.values.flatten.compact.any? { |option| @options[option] }
|
||||
return true
|
||||
end
|
||||
|
||||
keys_by_type.keys.each do |type|
|
||||
enforce = enforce_ssl_for?(keys_by_type[type], req)
|
||||
|
||||
next unless enforce
|
||||
|
||||
keys_by_type.each do |other_type,keys|
|
||||
next if type == other_type || !keys.any? { |option| @options[option] }
|
||||
|
||||
enforce = enforce_ssl_for?(keys, req)
|
||||
|
||||
break unless enforce
|
||||
end
|
||||
|
||||
break if enforce
|
||||
end
|
||||
|
||||
enforce
|
||||
end
|
||||
|
||||
def replace_scheme(req, scheme)
|
||||
|
|
Загрузка…
Ссылка в новой задаче