~michaelforrest/use-case-mapper/trunk

« back to all changes in this revision

Viewing changes to vendor/rails/actionpack/lib/action_controller/headers.rb

  • Committer: Michael Forrest
  • Date: 2010-10-15 16:28:50 UTC
  • Revision ID: michael.forrest@canonical.com-20101015162850-tj2vchanv0kr0dun
refrozeĀ gems

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
require 'active_support/memoizable'
 
2
 
 
3
module ActionController
 
4
  module Http
 
5
    class Headers < ::Hash
 
6
      extend ActiveSupport::Memoizable
 
7
 
 
8
      def initialize(*args)
 
9
         if args.size == 1 && args[0].is_a?(Hash)
 
10
           super()
 
11
           update(args[0])
 
12
         else
 
13
           super
 
14
         end
 
15
       end
 
16
 
 
17
      def [](header_name)
 
18
        if include?(header_name)
 
19
          super
 
20
        else
 
21
          super(env_name(header_name))
 
22
        end
 
23
      end
 
24
 
 
25
      private
 
26
        # Converts a HTTP header name to an environment variable name.
 
27
        def env_name(header_name)
 
28
          "HTTP_#{header_name.upcase.gsub(/-/, '_')}"
 
29
        end
 
30
        memoize :env_name
 
31
    end
 
32
  end
 
33
end