module Sinatra::Helpers

def attachment(filename = nil, disposition = :attachment)

instructing the user agents to prompt to save.
Set the Content-Disposition to "attachment" with the specified filename,
def attachment(filename = nil, disposition = :attachment)
  response['Content-Disposition'] = disposition.to_s.dup
  return unless filename
  params = format('; filename="%s"', File.basename(filename).gsub(/["\r\n]/, MULTIPART_FORM_DATA_REPLACEMENT_TABLE))
  response['Content-Disposition'] << params
  ext = File.extname(filename)
  content_type(ext) unless response['content-type'] || ext.empty?
end