2008-08-08 02:43:12 -04:00
|
|
|
require 'active_support/memoizable'
|
|
|
|
|
2009-01-27 19:54:01 -05:00
|
|
|
module ActionDispatch
|
2008-01-11 01:39:56 -05:00
|
|
|
module Http
|
|
|
|
class Headers < ::Hash
|
2008-08-08 02:43:12 -04:00
|
|
|
extend ActiveSupport::Memoizable
|
|
|
|
|
|
|
|
def initialize(*args)
|
2009-12-28 19:28:26 -05:00
|
|
|
if args.size == 1 && args[0].is_a?(Hash)
|
|
|
|
super()
|
|
|
|
update(args[0])
|
|
|
|
else
|
|
|
|
super
|
|
|
|
end
|
|
|
|
end
|
2008-08-08 02:43:12 -04:00
|
|
|
|
2008-01-11 01:39:56 -05:00
|
|
|
def [](header_name)
|
|
|
|
if include?(header_name)
|
2008-08-08 02:43:12 -04:00
|
|
|
super
|
2008-01-11 01:39:56 -05:00
|
|
|
else
|
2008-08-08 02:43:12 -04:00
|
|
|
super(env_name(header_name))
|
2008-01-11 01:39:56 -05:00
|
|
|
end
|
|
|
|
end
|
2008-08-08 02:43:12 -04:00
|
|
|
|
2008-01-11 01:39:56 -05:00
|
|
|
private
|
2008-08-08 02:43:12 -04:00
|
|
|
# Converts a HTTP header name to an environment variable name.
|
|
|
|
def env_name(header_name)
|
2008-01-11 01:39:56 -05:00
|
|
|
"HTTP_#{header_name.upcase.gsub(/-/, '_')}"
|
|
|
|
end
|
2008-08-08 02:43:12 -04:00
|
|
|
memoize :env_name
|
2008-01-11 01:39:56 -05:00
|
|
|
end
|
|
|
|
end
|
2008-08-08 02:43:12 -04:00
|
|
|
end
|