Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@chrisroos
Created September 27, 2017 14:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save chrisroos/1e9a98ef60b49096273df379b57de69e to your computer and use it in GitHub Desktop.
Save chrisroos/1e9a98ef60b49096273df379b57de69e to your computer and use it in GitHub Desktop.
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