Created
March 22, 2010 17:53
-
-
Save jdunphy/340319 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment