From 104f31af1dc412160b624da1b09c5456fa862f53 Mon Sep 17 00:00:00 2001 From: Michael Koziarski Date: Fri, 11 Jan 2008 06:39:56 +0000 Subject: Provide a nicer way to access headers. request.headers["Content-Type"] instead of request.headers["HTTP_CONTENT_TYPE"] [Koz] git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@8625 5ecf4fe2-1ee6-0310-87b1-e25e094e27de --- actionpack/lib/action_controller/headers.rb | 31 +++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100644 actionpack/lib/action_controller/headers.rb (limited to 'actionpack/lib/action_controller/headers.rb') diff --git a/actionpack/lib/action_controller/headers.rb b/actionpack/lib/action_controller/headers.rb new file mode 100644 index 0000000000..7239438c49 --- /dev/null +++ b/actionpack/lib/action_controller/headers.rb @@ -0,0 +1,31 @@ +module ActionController + module Http + class Headers < ::Hash + + def initialize(constructor = {}) + if constructor.is_a?(Hash) + super() + update(constructor) + else + super(constructor) + end + end + + def [](header_name) + if include?(header_name) + super + else + super(normalize_header(header_name)) + end + end + + + private + # Takes an HTTP header name and returns it in the + # format + def normalize_header(header_name) + "HTTP_#{header_name.upcase.gsub(/-/, '_')}" + end + end + end +end \ No newline at end of file -- cgit v1.2.3