Sha256: ed9aad4542ca2b83e7acd535338d112afed77489b444bdeea4ef10771ec77eca
Contents?: true
Size: 673 Bytes
Versions: 10
Compression:
Stored size: 673 Bytes
Contents
require 'rack' require 'rack/utils' module Murlsh # Rack middleware to force caches to always revalidate for urls that match # patterns. class MustRevalidate def initialize(app, options={}) @app = app @patterns = options[:patterns] ? [*options[:patterns]] : [] end def call(env) status, headers, body = @app.call(env) req = Rack::Request.new(env) headers = Rack::Utils::HeaderHash.new(headers) @patterns.each do |pattern| if pattern.match(req.path) headers['Cache-Control'] = 'must-revalidate, max-age=0' break end end [status, headers, body] end end end
Version data entries
10 entries across 10 versions & 1 rubygems