Sha256: a8756c7ff8f076ab57bdcb10e9927cbd22899adb759b93e668c62344d01abc78

Contents?: true

Size: 699 Bytes

Versions: 1

Compression:

Stored size: 699 Bytes

Contents

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

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
halorgium-actionpack-3.0.pre lib/action_dispatch/http/headers.rb