class Rack::CacheSmash
Constants
- HTML_CONTENT_TYPE_REGEXP
- PATHS_TO_CACHE_SMASH_REGEXP
- VERSION
Public Class Methods
new(app)
click to toggle source
# File lib/rack-cache-smash.rb, line 6 def initialize(app) @app = app end
Public Instance Methods
call(env)
click to toggle source
# File lib/rack-cache-smash.rb, line 10 def call(env) response = @app.call(env) headers = response[1] return response unless html_response?(headers) status = response.first original_body_arr = response.last body_str = cache_bust_asset_paths_in_body(original_body_arr) return [status, headers, [body_str]] end
Private Instance Methods
cache_bust_asset_paths_in_body(original_body_arr)
click to toggle source
# File lib/rack-cache-smash.rb, line 30 def cache_bust_asset_paths_in_body(original_body_arr) body_str = '' original_body_arr.each { |part| body_str << part } timestamp = Time.now.utc.to_i body_str.gsub!(PATHS_TO_CACHE_SMASH_REGEXP) do |match| query_string_suffix = $~[:query_string] ? "&#{$~[:query_string]}" : '' "#{$~[:ext]}?cachesmasher=#{timestamp}#{query_string_suffix}#{$~[:end_quote]}" end return body_str end
html_response?(headers)
click to toggle source
# File lib/rack-cache-smash.rb, line 26 def html_response?(headers) headers['Content-Type'] =~ HTML_CONTENT_TYPE_REGEXP end