From 644651dd38272c285459d807fd8e2db86275ec3e Mon Sep 17 00:00:00 2001 From: Vinicius Stock Date: Fri, 20 Mar 2020 14:05:22 -0400 Subject: [PATCH] Simplify renderer normalize keys --- actionpack/lib/action_controller/renderer.rb | 23 ++++++++++++-------- 1 file changed, 14 insertions(+), 9 deletions(-) diff --git a/actionpack/lib/action_controller/renderer.rb b/actionpack/lib/action_controller/renderer.rb index 5fabea6a10..d91c40c054 100644 --- a/actionpack/lib/action_controller/renderer.rb +++ b/actionpack/lib/action_controller/renderer.rb @@ -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