mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
Enable ActionDispatch::Http::Headers to support fetch
This commit is contained in:
parent
6a4541d63e
commit
61ba0fe82c
2 changed files with 13 additions and 7 deletions
|
@ -14,17 +14,18 @@ module ActionDispatch
|
||||||
end
|
end
|
||||||
|
|
||||||
def [](header_name)
|
def [](header_name)
|
||||||
if include?(header_name)
|
super env_name(header_name)
|
||||||
super
|
end
|
||||||
else
|
|
||||||
super(env_name(header_name))
|
def fetch(header_name, default=nil, &block)
|
||||||
end
|
super env_name(header_name), default, &block
|
||||||
end
|
end
|
||||||
|
|
||||||
private
|
private
|
||||||
# Converts a HTTP header name to an environment variable name.
|
# Converts a HTTP header name to an environment variable name if it is
|
||||||
|
# not contained within the headers hash.
|
||||||
def env_name(header_name)
|
def env_name(header_name)
|
||||||
@@env_cache[header_name]
|
include?(header_name) ? header_name : @@env_cache[header_name]
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -13,4 +13,9 @@ class HeaderTest < ActiveSupport::TestCase
|
||||||
assert_equal "text/plain", @headers["CONTENT_TYPE"]
|
assert_equal "text/plain", @headers["CONTENT_TYPE"]
|
||||||
assert_equal "text/plain", @headers["HTTP_CONTENT_TYPE"]
|
assert_equal "text/plain", @headers["HTTP_CONTENT_TYPE"]
|
||||||
end
|
end
|
||||||
|
|
||||||
|
test "fetch" do
|
||||||
|
assert_equal "text/plain", @headers.fetch("content-type", nil)
|
||||||
|
assert_equal "not found", @headers.fetch('not-found', 'not found')
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in a new issue