aboutsummaryrefslogtreecommitdiffstats
path: root/actionpack/lib/action_dispatch/http/headers.rb
diff options
context:
space:
mode:
authorJoshua Peek <josh@joshpeek.com>2009-01-27 18:54:01 -0600
committerJoshua Peek <josh@joshpeek.com>2009-01-27 18:54:01 -0600
commit319ae4628f4e0058de3e40e4ca7791b17e45e70c (patch)
treee5da1bfe6dd69a9cf483c9ff9fd18c5bfdd2f463 /actionpack/lib/action_dispatch/http/headers.rb
parenta0f2b1d95d3785de92ae271fd7ea23e91c0cadc6 (diff)
downloadrails-319ae4628f4e0058de3e40e4ca7791b17e45e70c.tar.gz
rails-319ae4628f4e0058de3e40e4ca7791b17e45e70c.tar.bz2
rails-319ae4628f4e0058de3e40e4ca7791b17e45e70c.zip
Move HTTP libs and middleware into ActionDispatch component
Diffstat (limited to 'actionpack/lib/action_dispatch/http/headers.rb')
-rw-r--r--actionpack/lib/action_dispatch/http/headers.rb33
1 files changed, 33 insertions, 0 deletions
diff --git a/actionpack/lib/action_dispatch/http/headers.rb b/actionpack/lib/action_dispatch/http/headers.rb
new file mode 100644
index 0000000000..2a41b4dbad
--- /dev/null
+++ b/actionpack/lib/action_dispatch/http/headers.rb
@@ -0,0 +1,33 @@
+require 'active_support/memoizable'
+
+module ActionDispatch
+ module Http
+ class Headers < ::Hash
+ extend ActiveSupport::Memoizable
+
+ def initialize(*args)
+ if args.size == 1 && args[0].is_a?(Hash)
+ super()
+ update(args[0])
+ else
+ super
+ end
+ end
+
+ def [](header_name)
+ if include?(header_name)
+ super
+ else
+ super(env_name(header_name))
+ end
+ end
+
+ private
+ # 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