module Sinatra::Helpers
def send_file(path, opts={})
def send_file(path, opts={}) stat = File.stat(path) last_modified stat.mtime if opts[:type] or not response['Content-Type'] content_type opts[:type] || File.extname(path), :default => 'application/octet-stream' end if opts[:disposition] == 'attachment' || opts[:filename] attachment opts[:filename] || path elsif opts[:disposition] == 'inline' response['Content-Disposition'] = 'inline' end file_length = opts[:length] || stat.size sf = StaticFile.open(path, 'rb') if ! sf.parse_ranges(env, file_length) response['Content-Range'] = "bytes */#{file_length}" halt 416 elsif r=sf.range response['Content-Range'] = "bytes #{r.begin}-#{r.end}/#{file_length}" response['Content-Length'] = (r.end - r.begin + 1).to_s halt 206, sf else response['Content-Length'] ||= file_length.to_s halt sf end rescue Errno::ENOENT not_found end