aboutsummaryrefslogblamecommitdiffstats
path: root/actionpack/lib/action_dispatch/http/headers.rb
blob: 2a41b4dbad7db6ec563f8b1825ef413a9eb0c993 (plain) (tree)
1
2
3
4
5
6
7
8
9

                                   
                     

                          



                                                 
                  
                          
             
                

            
 

                                
               
            
                                      

           
 
             

                                                                      

                                                     
                         

       
   
require 'active_support/memoizable'

module ActionDispatch
  module Http
    class Headers < ::Hash
      extend ActiveSupport::Memoizable

      def initialize(*args)
         if args.size == 1 && args[0].is_a?(Hash)
           super()
           update(args[0])
         else
           super
         end
       end

      def [](header_name)
        if include?(header_name)
          super
        else
          super(env_name(header_name))
        end
      end

      private
        # Converts a HTTP header name to an environment variable name.
        def env_name(header_name)
          "HTTP_#{header_name.upcase.gsub(/-/, '_')}"
        end
        memoize :env_name
    end
  end
end