Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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
You can’t perform that action at this time.