cache_buster.rb 617 B

12345678910111213141516171819202122232425262728
  1. # frozen_string_literal: true
  2. class CacheBuster
  3. def initialize(options = {})
  4. @secret_header = options[:secret_header] || 'Secret-Header'
  5. @secret = options[:secret] || 'True'
  6. end
  7. def bust(url)
  8. site = Addressable::URI.parse(url).normalized_site
  9. request_pool.with(site) do |http_client|
  10. build_request(url, http_client).perform
  11. end
  12. end
  13. private
  14. def request_pool
  15. RequestPool.current
  16. end
  17. def build_request(url, http_client)
  18. Request.new(:get, url, http_client: http_client).tap do |request|
  19. request.add_headers(@secret_header => @secret)
  20. end
  21. end
  22. end