summary refs log tree commit
path: root/lib/rack/etag.rb
diff options
context:
space:
mode:
Diffstat (limited to 'lib/rack/etag.rb')
-rw-r--r--lib/rack/etag.rb13
1 files changed, 7 insertions, 6 deletions
diff --git a/lib/rack/etag.rb b/lib/rack/etag.rb
index fefe671f..88973131 100644
--- a/lib/rack/etag.rb
+++ b/lib/rack/etag.rb
@@ -11,6 +11,7 @@ module Rack
   # used when Etag is absent and a directive when it is present. The first
   # defaults to nil, while the second defaults to "max-age=0, private, must-revalidate"
   class ETag
+    ETAG_STRING = 'ETag'.freeze
     DEFAULT_CACHE_CONTROL = "max-age=0, private, must-revalidate".freeze
 
     def initialize(app, no_cache_control = nil, cache_control = DEFAULT_CACHE_CONTROL)
@@ -28,14 +29,14 @@ module Rack
         body = Rack::BodyProxy.new(new_body) do
           original_body.close if original_body.respond_to?(:close)
         end
-        headers['ETag'] = %(W/"#{digest}") if digest
+        headers[ETAG_STRING] = %(W/"#{digest}") if digest
       end
 
-      unless headers['Cache-Control']
+      unless headers[CACHE_CONTROL]
         if digest
-          headers['Cache-Control'] = @cache_control if @cache_control
+          headers[CACHE_CONTROL] = @cache_control if @cache_control
         else
-          headers['Cache-Control'] = @no_cache_control if @no_cache_control
+          headers[CACHE_CONTROL] = @no_cache_control if @no_cache_control
         end
       end
 
@@ -53,8 +54,8 @@ module Rack
       end
 
       def skip_caching?(headers)
-        (headers['Cache-Control'] && headers['Cache-Control'].include?('no-cache')) ||
-          headers.key?('ETag') || headers.key?('Last-Modified')
+        (headers[CACHE_CONTROL] && headers[CACHE_CONTROL].include?('no-cache')) ||
+          headers.key?(ETAG_STRING) || headers.key?('Last-Modified')
       end
 
       def digest_body(body)