aboutsummaryrefslogtreecommitdiffstats
path: root/actionpack/lib/action_controller/headers.rb
diff options
context:
space:
mode:
authorJeremy Kemper <jeremy@bitsweat.net>2008-08-07 23:43:12 -0700
committerJeremy Kemper <jeremy@bitsweat.net>2008-08-07 23:43:12 -0700
commitb7529ed1cc7cfd8df5fd1b069e2881d39d3d984c (patch)
treeef69ba48ba47e42981101aab20aebae1d111c684 /actionpack/lib/action_controller/headers.rb
parente43d1c226d09afe49b25f5e3a351c4c10371933a (diff)
downloadrails-b7529ed1cc7cfd8df5fd1b069e2881d39d3d984c.tar.gz
rails-b7529ed1cc7cfd8df5fd1b069e2881d39d3d984c.tar.bz2
rails-b7529ed1cc7cfd8df5fd1b069e2881d39d3d984c.zip
Simplifying usage of ETags and Last-Modified and conditional GET requests
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