Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
assets_checked = 0
assets_without_content_type = 0
percentage_of_assets_to_test = 0.1
assets = Asset.all
assets.each.with_index do |asset, index|
next unless (rand * 100) < percentage_of_assets_to_test
id = asset.id
filename = asset.read_attribute(:file)
url = "https://assets.publishing.service.gov.uk/media/#{id}/#{filename}"
response = `curl -Is "#{url}"`
response_code = (response[/HTTP\/1.1 (.*)/, 1] || '').chomp
content_type = (response[/Content-Type: (.*)/, 1] || '').chomp
puts [url, response_code, content_type].join(',')
assets_checked += 1
if content_type.blank? && response_code =~ /200/
assets_without_content_type += 1
end
end
puts "Assets checked: #{assets_checked}"
puts "Assets without Content-Type: #{assets_without_content_type}"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.