mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
Simplify renderer normalize keys
This commit is contained in:
parent
5df9b4584c
commit
644651dd38
1 changed files with 14 additions and 9 deletions
|
@ -103,8 +103,13 @@ module ActionController
|
||||||
private
|
private
|
||||||
def normalize_keys(defaults, env)
|
def normalize_keys(defaults, env)
|
||||||
new_env = {}
|
new_env = {}
|
||||||
defaults.each_pair { |k, v| new_env[rack_key_for(k)] = rack_value_for(k, v) }
|
|
||||||
env.each_pair { |k, v| new_env[rack_key_for(k)] = rack_value_for(k, v) }
|
env.each_pair { |k, v| new_env[rack_key_for(k)] = rack_value_for(k, v) }
|
||||||
|
|
||||||
|
defaults.each_pair do |k, v|
|
||||||
|
key = rack_key_for(k)
|
||||||
|
new_env[key] = rack_value_for(k, v) unless new_env.key?(key)
|
||||||
|
end
|
||||||
|
|
||||||
new_env["rack.url_scheme"] = new_env["HTTPS"] == "on" ? "https" : "http"
|
new_env["rack.url_scheme"] = new_env["HTTPS"] == "on" ? "https" : "http"
|
||||||
new_env
|
new_env
|
||||||
end
|
end
|
||||||
|
@ -117,19 +122,19 @@ module ActionController
|
||||||
input: "rack.input"
|
input: "rack.input"
|
||||||
}
|
}
|
||||||
|
|
||||||
IDENTITY = ->(_) { _ }
|
|
||||||
|
|
||||||
RACK_VALUE_TRANSLATION = {
|
|
||||||
https: ->(v) { v ? "on" : "off" },
|
|
||||||
method: ->(v) { -v.upcase },
|
|
||||||
}
|
|
||||||
|
|
||||||
def rack_key_for(key)
|
def rack_key_for(key)
|
||||||
RACK_KEY_TRANSLATION[key] || key.to_s
|
RACK_KEY_TRANSLATION[key] || key.to_s
|
||||||
end
|
end
|
||||||
|
|
||||||
def rack_value_for(key, value)
|
def rack_value_for(key, value)
|
||||||
RACK_VALUE_TRANSLATION.fetch(key, IDENTITY).call value
|
case key
|
||||||
|
when :https
|
||||||
|
value ? "on" : "off"
|
||||||
|
when :method
|
||||||
|
-value.upcase
|
||||||
|
else
|
||||||
|
value
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in a new issue