...
gem 'rack-proxy', require: 'rack/proxy'
...
config.ru
# frozen_string_literal: true
# This file is used by Rack-based servers to start the application.
require_relative 'config/environment'
class NilProxy < Rack::Proxy
def perform_request(env)
request = Rack::Request.new(env)
if request.path =~ %r{\.pdf}
env['HTTP_HOST'] = 'www.eff.org'
env['SERVER_PORT'] = '443'
env['PATH_INFO'] = '/files/filenode/readme.pdf'
env['rack.url_scheme'] = 'https'
super(env)
else
@app.call(env)
end
end
def rewrite_response(triplet)
status, headers, body = triplet
headers['Content-Type'] = 'application/pdf'
headers['Content-Disposition'] = 'attachment; filename=test.pdf'
[status, headers, body]
end
end
use NilProxy, ssl_verify_none: true
run Rails.application