Skip to content

Instantly share code, notes, and snippets.

@chrisroos
Created December 18, 2017 12:03
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/ebe39e5b6cfc396de5f42ac2bddcc3a6 to your computer and use it in GitHub Desktop.
Save chrisroos/ebe39e5b6cfc396de5f42ac2bddcc3a6 to your computer and use it in GitHub Desktop.
require 'net/http'
file_path = Rails.root.join('tmp', 'tmp.txt')
File.open(file_path, 'w') { |file| file.puts(Time.now) }
asset = Asset.create!(file: File.open(file_path))
def display_headers(response)
puts "Code: #{response.code}"
puts "Etag: #{response.header['Etag']}"
puts "Content-Type: #{response.header['Content-Type']}"
puts "Last-Modified: #{response.header['Last-Modified']}"
puts "X-Frame-Options: #{response.header['X-Frame-Options']}"
end
puts "Waiting for asset to be virus scanned"
until asset.clean?
sleep 1
asset.reload
end
puts "Waiting for asset to be uploaded to S3"
until Services.cloud_storage.exists?(asset)
sleep 1
end
puts '---'
puts "Responses from Rails app"
response = Net::HTTP.get_response(URI('http://localhost:3037' + asset.public_url_path))
display_headers(response)
puts '---'
puts "Responses from S3 object"
redirect_to = response.header['X-Accel-Redirect'].sub(/^\/cloud-storage-proxy\//, '')
response = Net::HTTP.get_response(URI(redirect_to))
display_headers(response)
puts '---'
puts "Responses from Asset Manager nginx"
response = Net::HTTP.get_response(URI('http://asset-manager.dev.gov.uk' + asset.public_url_path))
display_headers(response)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment