class Kiss class StaticFile def initialize(path, options = {}) @_path = path @_options = options end def finish ext = File.extname(@_path)[1..-1] headers = { "Last-Modified" => File.mtime(@_path).rfc822, "Content-Type" => @_options[:type] || Kiss.mime_type(ext) || "text/plain", "Content-Length" => File.size(@_path).to_s } if @_options[:filename] headers['Content-Disposition'] = "#{@_options[:disposition] || 'inline'}; filename=#{@_options[:filename]}" elsif @_options[:disposition] headers['Content-Disposition'] = @_options[:disposition] end if File.file?(@_path) && File.readable?(@_path) [200, headers, self] else raise "file not found: #{@_path}" end end def each File.open(@_path, "rb") { |file| while part = file.read(8192) yield part end } end end end