diff options
author | Rafael Mendonça França <rafaelmfranca@gmail.com> | 2012-07-29 22:48:20 -0700 |
---|---|---|
committer | Rafael Mendonça França <rafaelmfranca@gmail.com> | 2012-07-29 22:48:20 -0700 |
commit | 69f62ecaff66c25b62c5d9cad41c62fc74d717c5 (patch) | |
tree | 6c7413cbe5cf28d38538a7955663dc7713488eb5 /actionpack/lib | |
parent | 0899be5798d20e3e886e5f741d3e4b1bf43afedd (diff) | |
parent | 7db29f900400e9f35142ede94148d3a71e651adb (diff) | |
download | rails-69f62ecaff66c25b62c5d9cad41c62fc74d717c5.tar.gz rails-69f62ecaff66c25b62c5d9cad41c62fc74d717c5.tar.bz2 rails-69f62ecaff66c25b62c5d9cad41c62fc74d717c5.zip |
Merge pull request #7198 from cfcosta/refactor-cache_control_headers
Refactor ActionDispatch::Http::Cache::Response#cache_control_headers
Diffstat (limited to 'actionpack/lib')
-rw-r--r-- | actionpack/lib/action_dispatch/http/cache.rb | 30 |
1 files changed, 19 insertions, 11 deletions
diff --git a/actionpack/lib/action_dispatch/http/cache.rb b/actionpack/lib/action_dispatch/http/cache.rb index 0b895e7860..647a9e3c19 100644 --- a/actionpack/lib/action_dispatch/http/cache.rb +++ b/actionpack/lib/action_dispatch/http/cache.rb @@ -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 |