diff options
author | Jeremy Kemper <jeremy@bitsweat.net> | 2008-08-12 17:03:17 -0700 |
---|---|---|
committer | Jeremy Kemper <jeremy@bitsweat.net> | 2008-08-12 17:03:17 -0700 |
commit | 45b79d933cd2433b30ae98e7dadc4ae060e170c9 (patch) | |
tree | 6bc79848cf6aab926cdcfb51b298fe26b68a0ec0 /actionpack/lib/action_controller/headers.rb | |
parent | 992fda16ed662f028700d63a8dcbd1837f1d58ab (diff) | |
parent | 08b0cf07dbc639c8609118eaeb34330d5168e8b2 (diff) | |
download | rails-45b79d933cd2433b30ae98e7dadc4ae060e170c9.tar.gz rails-45b79d933cd2433b30ae98e7dadc4ae060e170c9.tar.bz2 rails-45b79d933cd2433b30ae98e7dadc4ae060e170c9.zip |
Merge branch 'conditional-get'
Diffstat (limited to 'actionpack/lib/action_controller/headers.rb')
-rw-r--r-- | actionpack/lib/action_controller/headers.rb | 30 |
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 |