aboutsummaryrefslogtreecommitdiffstats
path: root/actionpack/lib/action_dispatch/http/headers.rb
diff options
context:
space:
mode:
authorAaron Patterson <aaron.patterson@gmail.com>2015-08-21 16:57:07 -0700
committerAaron Patterson <aaron.patterson@gmail.com>2015-08-21 16:59:13 -0700
commitbce4ff70dd1ab88e5b573ad8c88408f100cf219e (patch)
tree10bebf1887dc3506650f9210c02072a7db04dd44 /actionpack/lib/action_dispatch/http/headers.rb
parentc0c726849bf697f6c76b86e704ca51b04e252341 (diff)
downloadrails-bce4ff70dd1ab88e5b573ad8c88408f100cf219e.tar.gz
rails-bce4ff70dd1ab88e5b573ad8c88408f100cf219e.tar.bz2
rails-bce4ff70dd1ab88e5b573ad8c88408f100cf219e.zip
use methods on the request object to implement `fetch`
Now the Headers internals don't depend on the env hash.
Diffstat (limited to 'actionpack/lib/action_dispatch/http/headers.rb')
-rw-r--r--actionpack/lib/action_dispatch/http/headers.rb10
1 files changed, 8 insertions, 2 deletions
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)