aboutsummaryrefslogtreecommitdiffstats
path: root/actionpack/lib/action_dispatch/http/headers.rb
diff options
context:
space:
mode:
authorAaron Patterson <aaron.patterson@gmail.com>2015-08-20 15:57:15 -0700
committerAaron Patterson <aaron.patterson@gmail.com>2015-08-21 11:21:10 -0700
commit34fa6658dd1b779b21e586f01ee64c6f59ca1537 (patch)
tree28b43f910a8c88c17b88f9ec991c0bdf89f86de9 /actionpack/lib/action_dispatch/http/headers.rb
parentc6cfcc6124fdef4df3a406f389ba32be486cd437 (diff)
downloadrails-34fa6658dd1b779b21e586f01ee64c6f59ca1537.tar.gz
rails-34fa6658dd1b779b21e586f01ee64c6f59ca1537.tar.bz2
rails-34fa6658dd1b779b21e586f01ee64c6f59ca1537.zip
pass a request object to the headers object
Diffstat (limited to 'actionpack/lib/action_dispatch/http/headers.rb')
-rw-r--r--actionpack/lib/action_dispatch/http/headers.rb24
1 files changed, 15 insertions, 9 deletions
diff --git a/actionpack/lib/action_dispatch/http/headers.rb b/actionpack/lib/action_dispatch/http/headers.rb
index bc5410dc38..40053e521a 100644
--- a/actionpack/lib/action_dispatch/http/headers.rb
+++ b/actionpack/lib/action_dispatch/http/headers.rb
@@ -30,24 +30,27 @@ module ActionDispatch
HTTP_HEADER = /\A[A-Za-z0-9-]+\z/
include Enumerable
- attr_reader :env
- def initialize(env = {}) # :nodoc:
- @env = env
+ def self.from_hash(hash)
+ new ActionDispatch::Request.new hash
+ end
+
+ def initialize(request) # :nodoc:
+ @req = request
end
# Returns the value for the given key mapped to @env.
def [](key)
- @env[env_name(key)]
+ env[env_name(key)]
end
# Sets the given value for the key mapped to @env.
def []=(key, value)
- @env[env_name(key)] = value
+ env[env_name(key)] = value
end
def key?(key)
- @env.key? env_name(key)
+ env.key? env_name(key)
end
alias :include? :key?
@@ -59,17 +62,17 @@ 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
+ env.fetch env_name(key), *args, &block
end
def each(&block)
- @env.each(&block)
+ env.each(&block)
end
# Returns a new Http::Headers instance containing the contents of
# <tt>headers_or_env</tt> and the original instance.
def merge(headers_or_env)
- headers = Http::Headers.new(env.dup)
+ headers = Http::Headers.new(ActionDispatch::Request.new(env.dup))
headers.merge!(headers_or_env)
headers
end
@@ -83,7 +86,10 @@ module ActionDispatch
end
end
+ def env; @req.env; end
+
private
+
# Converts a HTTP header name to an environment variable name if it is
# not contained within the headers hash.
def env_name(key)