Skip to content
Browse files

Enable ActionDispatch::Http::Headers to support fetch

  • Loading branch information...
1 parent 6a4541d commit 61ba0fe82c440d244d70afc9aad5c8ea9d6e810d @amerine amerine committed
Showing with 13 additions and 7 deletions.
  1. +8 −7 actionpack/lib/action_dispatch/http/headers.rb
  2. +5 −0 actionpack/test/dispatch/header_test.rb
View
15 actionpack/lib/action_dispatch/http/headers.rb
@@ -14,17 +14,18 @@ def initialize(*args)
end
def [](header_name)
- if include?(header_name)
- super
- else
- super(env_name(header_name))
- end
+ super env_name(header_name)
+ end
+
+ def fetch(header_name, default=nil, &block)
+ super env_name(header_name), default, &block
end
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)
- @@env_cache[header_name]
+ include?(header_name) ? header_name : @@env_cache[header_name]
end
end
end
View
5 actionpack/test/dispatch/header_test.rb
@@ -13,4 +13,9 @@ def setup
assert_equal "text/plain", @headers["CONTENT_TYPE"]
assert_equal "text/plain", @headers["HTTP_CONTENT_TYPE"]
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

0 comments on commit 61ba0fe

Please sign in to comment.
Something went wrong with that request. Please try again.