mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
Merge pull request #7198 from cfcosta/refactor-cache_control_headers
Refactor ActionDispatch::Http::Cache::Response#cache_control_headers
This commit is contained in:
commit
69f62ecaff
1 changed files with 19 additions and 11 deletions
|
@ -86,21 +86,29 @@ module ActionDispatch
|
|||
CACHE_CONTROL = "Cache-Control".freeze
|
||||
SPESHUL_KEYS = %w[extras no-cache max-age public must-revalidate]
|
||||
|
||||
def cache_control_segments
|
||||
if cache_control = self[CACHE_CONTROL]
|
||||
cache_control.delete(' ').split(',')
|
||||
else
|
||||
[]
|
||||
end
|
||||
end
|
||||
|
||||
def cache_control_headers
|
||||
cache_control = {}
|
||||
if cc = self[CACHE_CONTROL]
|
||||
cc.delete(' ').split(',').each do |segment|
|
||||
directive, argument = segment.split('=', 2)
|
||||
case directive
|
||||
when *SPESHUL_KEYS
|
||||
key = directive.tr('-', '_')
|
||||
cache_control[key.to_sym] = argument || true
|
||||
else
|
||||
cache_control[:extras] ||= []
|
||||
cache_control[:extras] << segment
|
||||
end
|
||||
|
||||
cache_control_segments.each do |segment|
|
||||
directive, argument = segment.split('=', 2)
|
||||
|
||||
if SPESHUL_KEYS.include? directive
|
||||
key = directive.tr('-', '_')
|
||||
cache_control[key.to_sym] = argument || true
|
||||
else
|
||||
cache_control[:extras] ||= []
|
||||
cache_control[:extras] << segment
|
||||
end
|
||||
end
|
||||
|
||||
cache_control
|
||||
end
|
||||
|
||||
|
|
Loading…
Reference in a new issue