aboutsummaryrefslogtreecommitdiffstats
path: root/actionpack/lib/action_controller
diff options
context:
space:
mode:
Diffstat (limited to 'actionpack/lib/action_controller')
-rw-r--r--actionpack/lib/action_controller/headers.rb31
-rwxr-xr-xactionpack/lib/action_controller/request.rb4
2 files changed, 34 insertions, 1 deletions
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
diff --git a/actionpack/lib/action_controller/request.rb b/actionpack/lib/action_controller/request.rb
index c48426d377..e3892037d8 100755
--- a/actionpack/lib/action_controller/request.rb
+++ b/actionpack/lib/action_controller/request.rb
@@ -61,8 +61,10 @@ module ActionController
request_method == :head
end
+ # Provides acccess to the request's HTTP headers, for example:
+ # request.headers["Content-Type"] # => "text/plain"
def headers
- @env
+ @headers ||= ActionController::Http::Headers.new(@env)
end
def content_length