diff options
author | Aaron Patterson <aaron.patterson@gmail.com> | 2017-09-05 09:44:54 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-09-05 09:44:54 -0700 |
commit | 18f342d82a380d5bd23c33018818224d32b69a95 (patch) | |
tree | bd4e9c644af6e566244cdb4b49134a3b03abe746 /actionpack/lib/action_dispatch | |
parent | 6c4a32e27ddadc58673a36f47ca28f74b09c9ed0 (diff) | |
parent | 651ec51fc5b3d044083d301e571ff108ab02d62f (diff) | |
download | rails-18f342d82a380d5bd23c33018818224d32b69a95.tar.gz rails-18f342d82a380d5bd23c33018818224d32b69a95.tar.bz2 rails-18f342d82a380d5bd23c33018818224d32b69a95.zip |
Merge pull request #30367 from ptoomey3/consistent-cache-control-headers
Normalize/process Cache-Control headers consistently
Diffstat (limited to 'actionpack/lib/action_dispatch')
-rw-r--r-- | actionpack/lib/action_dispatch/http/cache.rb | 20 | ||||
-rw-r--r-- | actionpack/lib/action_dispatch/http/response.rb | 1 |
2 files changed, 13 insertions, 8 deletions
diff --git a/actionpack/lib/action_dispatch/http/cache.rb b/actionpack/lib/action_dispatch/http/cache.rb index 8073685b78..3328ce17a0 100644 --- a/actionpack/lib/action_dispatch/http/cache.rb +++ b/actionpack/lib/action_dispatch/http/cache.rb @@ -166,19 +166,23 @@ module ActionDispatch @cache_control = cache_control_headers end - def handle_conditional_get! - if etag? || last_modified? || !@cache_control.empty? - set_conditional_cache_control!(@cache_control) - end - end - DEFAULT_CACHE_CONTROL = "max-age=0, private, must-revalidate".freeze NO_CACHE = "no-cache".freeze PUBLIC = "public".freeze PRIVATE = "private".freeze MUST_REVALIDATE = "must-revalidate".freeze - def set_conditional_cache_control!(cache_control) + def handle_conditional_get! + # Normally default cache control setting is handled by ETag + # middleware. But, if an etag is already set, the middleware + # defaults to `no-cache` unless a default `Cache-Control` value is + # previously set. So, set a default one here. + if (etag? || last_modified?) && !self._cache_control + self._cache_control = DEFAULT_CACHE_CONTROL + end + end + + def merge_and_normalize_cache_control!(cache_control) control = {} cc_headers = cache_control_headers if extras = cc_headers.delete(:extras) @@ -191,7 +195,7 @@ module ActionDispatch control.merge! cache_control if control.empty? - self._cache_control = DEFAULT_CACHE_CONTROL + # Let middleware handle default behavior elsif control[:no_cache] self._cache_control = NO_CACHE if control[:extras] diff --git a/actionpack/lib/action_dispatch/http/response.rb b/actionpack/lib/action_dispatch/http/response.rb index b314dbecfe..0c7b153420 100644 --- a/actionpack/lib/action_dispatch/http/response.rb +++ b/actionpack/lib/action_dispatch/http/response.rb @@ -433,6 +433,7 @@ module ActionDispatch # :nodoc: def before_committed return if committed? assign_default_content_type_and_charset! + merge_and_normalize_cache_control!(@cache_control) handle_conditional_get! handle_no_content! end |