forked from rails/rails
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Simplifying usage of ETags and Last-Modified and conditional GET requ…
…ests
- Loading branch information
Showing
7 changed files
with
169 additions
and
135 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,31 +1,33 @@ | ||
require 'active_support/memoizable' | ||
|
||
module ActionController | ||
module Http | ||
class Headers < ::Hash | ||
|
||
def initialize(constructor = {}) | ||
if constructor.is_a?(Hash) | ||
extend ActiveSupport::Memoizable | ||
|
||
def initialize(*args) | ||
if args.size == 1 && args[0].is_a?(Hash) | ||
super() | ||
update(constructor) | ||
update(args[0]) | ||
else | ||
super(constructor) | ||
super | ||
end | ||
end | ||
|
||
def [](header_name) | ||
if include?(header_name) | ||
super | ||
super | ||
else | ||
super(normalize_header(header_name)) | ||
super(env_name(header_name)) | ||
end | ||
end | ||
|
||
|
||
|
||
private | ||
# Takes an HTTP header name and returns it in the | ||
# format | ||
def normalize_header(header_name) | ||
# 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 | ||
end |
Oops, something went wrong.