Skip to content

Instantly share code, notes, and snippets.

@puyo
Last active December 19, 2015 22:28
Show Gist options
  • Save puyo/6027330 to your computer and use it in GitHub Desktop.
Save puyo/6027330 to your computer and use it in GitHub Desktop.
Make PDFKit middleware set content disposition so that .pdf links are downloaded.
require 'pdfkit'
class PDFKitMiddlewareDownload < PDFKit::Middleware
def call(env)
status, headers, response = super(env)
if headers['Content-Type'] == 'application/pdf'
headers['Content-Disposition'] = 'attachment'
end
[status, headers, response]
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment