cache_buster.rb 708 B

123456789101112131415161718192021222324252627282930
  1. # frozen_string_literal: true
  2. class CacheBuster
  3. def initialize(options = {})
  4. @secret_header = options[:secret_header]
  5. @secret = options[:secret]
  6. @http_method = options[:http_method] || 'GET'
  7. end
  8. def bust(url)
  9. site = Addressable::URI.parse(url).normalized_site
  10. request_pool.with(site) do |http_client|
  11. build_request(url, http_client).perform
  12. end
  13. end
  14. private
  15. def request_pool
  16. RequestPool.current
  17. end
  18. def build_request(url, http_client)
  19. request = Request.new(@http_method.downcase.to_sym, url, http_client: http_client)
  20. request.add_headers(@secret_header => @secret) if @secret_header.present? && @secret && !@secret.empty?
  21. request
  22. end
  23. end