Class: Rack::WWWhisper::NoPublicCache
- Inherits:
-
Object
- Object
- Rack::WWWhisper::NoPublicCache
- Defined in:
- lib/rack/wwwhisper.rb
Overview
An internal middleware used by Rack::WWWhisper to change directives that enable public caching into directives that enable private caching.
To be on a safe side, all wwwhisper protected content is treated as sensitive and not publicly cacheable.
Instance Method Summary collapse
-
#call(env) ⇒ Object
If a response enables caching, makes sure it is private.
-
#initialize(app) ⇒ NoPublicCache
constructor
A new instance of NoPublicCache.
Constructor Details
#initialize(app) ⇒ NoPublicCache
Returns a new instance of NoPublicCache.
289 290 291 |
# File 'lib/rack/wwwhisper.rb', line 289 def initialize(app) @app = app end |
Instance Method Details
#call(env) ⇒ Object
If a response enables caching, makes sure it is private.
294 295 296 297 298 299 300 301 302 303 304 305 306 307 |
# File 'lib/rack/wwwhisper.rb', line 294 def call(env) status, headers, body = @app.call(env) if cache_control = headers['Cache-Control'] cache_control = cache_control.gsub(/public/, 'private') if (not cache_control.include? 'private' and cache_control.index(/max-age\s*=\s*0*[1-9]/)) # max-age > 0 without 'public' or 'private' directive is # treated as 'public', so 'private' needs to be prepended. cache_control.insert(0, 'private, ') end headers['Cache-Control'] = cache_control end [status, headers, body] end |