提交 bce4ff70 编写于 作者: A Aaron Patterson

use methods on the request object to implement `fetch`

Now the Headers internals don't depend on the env hash.
上级 c0c72684
......@@ -54,6 +54,8 @@ def key?(key)
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 @@ def key?(key)
#
# 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)
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册