Method: Sinatra::Helpers#send_file
- Defined in:
- lib/sinatra/base.rb
#send_file(path, opts = {}) ⇒ Object
Use the contents of the file at +path+ as the response body.
428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 |
# File 'lib/sinatra/base.rb', line 428 def send_file(path, opts = {}) if opts[:type] || !response['content-type'] content_type opts[:type] || File.extname(path), default: 'application/octet-stream' end disposition = opts[:disposition] filename = opts[:filename] disposition = :attachment if disposition.nil? && filename filename = path if filename.nil? (filename, disposition) if disposition last_modified opts[:last_modified] if opts[:last_modified] file = Rack::Files.new(File.dirname(settings.app_file)) result = file.serving(request, path) result[1].each { |k, v| headers[k] ||= v } headers['content-length'] = result[1]['content-length'] opts[:status] &&= Integer(opts[:status]) halt (opts[:status] || result[0]), result[2] rescue Errno::ENOENT not_found end |