From bce4ff70dd1ab88e5b573ad8c88408f100cf219e Mon Sep 17 00:00:00 2001 From: Aaron Patterson Date: Fri, 21 Aug 2015 16:57:07 -0700 Subject: use methods on the request object to implement `fetch` Now the Headers internals don't depend on the env hash. --- actionpack/lib/action_dispatch/http/headers.rb | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) (limited to 'actionpack/lib/action_dispatch') diff --git a/actionpack/lib/action_dispatch/http/headers.rb b/actionpack/lib/action_dispatch/http/headers.rb index b70fee4a84..fbdec6c132 100644 --- a/actionpack/lib/action_dispatch/http/headers.rb +++ b/actionpack/lib/action_dispatch/http/headers.rb @@ -54,6 +54,8 @@ module ActionDispatch end alias :include? :key? + DEFAULT = Object.new # :nodoc: + # Returns the value for the given key mapped to @env. # # If the key is not found and an optional code block is not provided, @@ -61,8 +63,12 @@ module ActionDispatch # # If the code block is provided, then it will be run and # its result returned. - def fetch(key, *args, &block) - env.fetch env_name(key), *args, &block + def fetch(key, default = DEFAULT) + @req.get_header(env_name(key)) do + return default unless default == DEFAULT + return yield if block_given? + raise NameError, key + end end def each(&block) -- cgit v1.2.3