2008-10-27 07:47:01 +01:00
|
|
|
require 'active_support/memoizable'
|
|
|
|
|
2008-05-18 06:22:34 +02:00
|
|
|
module ActionController
|
|
|
|
module Http
|
|
|
|
class Headers < ::Hash
|
2008-10-27 07:47:01 +01:00
|
|
|
extend ActiveSupport::Memoizable
|
|
|
|
|
|
|
|
def initialize(*args)
|
|
|
|
if args.size == 1 && args[0].is_a?(Hash)
|
2008-05-18 06:22:34 +02:00
|
|
|
super()
|
2008-10-27 07:47:01 +01:00
|
|
|
update(args[0])
|
2008-05-18 06:22:34 +02:00
|
|
|
else
|
2008-10-27 07:47:01 +01:00
|
|
|
super
|
2008-05-18 06:22:34 +02:00
|
|
|
end
|
|
|
|
end
|
2008-10-27 07:47:01 +01:00
|
|
|
|
2008-05-18 06:22:34 +02:00
|
|
|
def [](header_name)
|
|
|
|
if include?(header_name)
|
2008-10-27 07:47:01 +01:00
|
|
|
super
|
2008-05-18 06:22:34 +02:00
|
|
|
else
|
2008-10-27 07:47:01 +01:00
|
|
|
super(env_name(header_name))
|
2008-05-18 06:22:34 +02:00
|
|
|
end
|
|
|
|
end
|
2008-10-27 07:47:01 +01:00
|
|
|
|
2008-05-18 06:22:34 +02:00
|
|
|
private
|
2008-10-27 07:47:01 +01:00
|
|
|
# Converts a HTTP header name to an environment variable name.
|
|
|
|
def env_name(header_name)
|
2008-05-18 06:22:34 +02:00
|
|
|
"HTTP_#{header_name.upcase.gsub(/-/, '_')}"
|
|
|
|
end
|
2008-10-27 07:47:01 +01:00
|
|
|
memoize :env_name
|
2008-05-18 06:22:34 +02:00
|
|
|
end
|
|
|
|
end
|
2008-10-27 07:47:01 +01:00
|
|
|
end
|