1
0
Fork 0
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:
Vinicius Stock 2020-03-20 14:05:22 -04:00
parent 5df9b4584c
commit 644651dd38
No known key found for this signature in database
GPG key ID: 1A3EC85374C0969A

View file

@ -103,8 +103,13 @@ module ActionController
private
def normalize_keys(defaults, 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) }
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
end
@ -117,19 +122,19 @@ module ActionController
input: "rack.input"
}
IDENTITY = ->(_) { _ }
RACK_VALUE_TRANSLATION = {
https: ->(v) { v ? "on" : "off" },
method: ->(v) { -v.upcase },
}
def rack_key_for(key)
RACK_KEY_TRANSLATION[key] || key.to_s
end
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