2020-11-19 17:38:06 +01:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
class CacheBuster
|
|
|
|
def initialize(options = {})
|
2024-06-21 17:32:49 +02:00
|
|
|
@secret_header = options[:secret_header]
|
|
|
|
@secret = options[:secret]
|
2023-08-18 08:18:40 +02:00
|
|
|
@http_method = options[:http_method] || 'GET'
|
2020-11-19 17:38:06 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
def bust(url)
|
|
|
|
site = Addressable::URI.parse(url).normalized_site
|
|
|
|
|
|
|
|
request_pool.with(site) do |http_client|
|
|
|
|
build_request(url, http_client).perform
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
def request_pool
|
|
|
|
RequestPool.current
|
|
|
|
end
|
|
|
|
|
|
|
|
def build_request(url, http_client)
|
2023-08-18 08:18:40 +02:00
|
|
|
request = Request.new(@http_method.downcase.to_sym, url, http_client: http_client)
|
|
|
|
request.add_headers(@secret_header => @secret) if @secret_header.present? && @secret && !@secret.empty?
|
|
|
|
|
|
|
|
request
|
2020-11-19 17:38:06 +01:00
|
|
|
end
|
|
|
|
end
|