Project

General

Profile

Feature #4477 » mime_type_and_inlne_repo_files.patch

Felix Schäfer, 2009-12-23 23:54

View differences:

app/controllers/repositories_controller.rb
115 115
    @content = @repository.cat(@path, @rev)
116 116
    show_error_not_found and return unless @content
117 117
    if 'raw' == params[:format] || @content.is_binary_data? || (@entry.size && @entry.size > Setting.file_max_size_displayed.to_i.kilobyte)
118
      # Try to guess the content-type
119
      en = @entry.name
120
      mime = Mime::Type.lookup_by_extension(en[en.rindex('.')+1, en.size].downcase) unless en.rindex('.').nil?
121
      options = { :filename => @path.split('/').last }
122
      options.merge!( :type => mime, :disposition => "inline" ) unless mime.nil?
118 123
      # Force the download
119
      send_data @content, :filename => @path.split('/').last
124
      send_data @content, options
120 125
    else
121 126
      # Prevent empty lines when displaying a file with Windows style eol
122 127
      @content.gsub!("\r\n", "\n")
    (1-1/1)