aboutsummaryrefslogtreecommitdiffstats
path: root/actionpack/lib/action_controller/headers.rb
diff options
context:
space:
mode:
authorPratik Naik <pratiknaik@gmail.com>2008-08-14 16:31:14 +0100
committerPratik Naik <pratiknaik@gmail.com>2008-08-14 16:31:14 +0100
commit2ebe8d275efa53af967b09ad66dab68acc1aed98 (patch)
treeb0b3e42c277b213788b55558aef3579f4e242300 /actionpack/lib/action_controller/headers.rb
parent73ef94e9675ef6db85f18f1e3c70bf6ddfc1260a (diff)
parent8cb14ee1203c9ed380c4b192e8730757a52d43cb (diff)
downloadrails-2ebe8d275efa53af967b09ad66dab68acc1aed98.tar.gz
rails-2ebe8d275efa53af967b09ad66dab68acc1aed98.tar.bz2
rails-2ebe8d275efa53af967b09ad66dab68acc1aed98.zip
Merge commit 'mainstream/master'
Conflicts: actionpack/lib/action_controller/request.rb actionpack/lib/action_controller/resources.rb
Diffstat (limited to 'actionpack/lib/action_controller/headers.rb')
-rw-r--r--actionpack/lib/action_controller/headers.rb30
1 files changed, 16 insertions, 14 deletions
diff --git a/actionpack/lib/action_controller/headers.rb b/actionpack/lib/action_controller/headers.rb
index 7239438c49..139669c66f 100644
--- a/actionpack/lib/action_controller/headers.rb
+++ b/actionpack/lib/action_controller/headers.rb
@@ -1,31 +1,33 @@
+require 'active_support/memoizable'
+
module ActionController
module Http
class Headers < ::Hash
-
- def initialize(constructor = {})
- if constructor.is_a?(Hash)
+ extend ActiveSupport::Memoizable
+
+ def initialize(*args)
+ if args.size == 1 && args[0].is_a?(Hash)
super()
- update(constructor)
+ update(args[0])
else
- super(constructor)
+ super
end
end
-
+
def [](header_name)
if include?(header_name)
- super
+ super
else
- super(normalize_header(header_name))
+ super(env_name(header_name))
end
end
-
-
+
private
- # Takes an HTTP header name and returns it in the
- # format
- def normalize_header(header_name)
+ # Converts a HTTP header name to an environment variable name.
+ def env_name(header_name)
"HTTP_#{header_name.upcase.gsub(/-/, '_')}"
end
+ memoize :env_name
end
end
-end \ No newline at end of file
+end