Commit aaad7fd973d88a49fe23f01cca6b2248ad7977d4

Authored by Jeroen van Baarsen
1 parent d41e404e

Fixes #6207 Allow raw download of *.msi files

This PR also allows for download of [exe,rar,r0n,7z,7zip,zip]
Fix was originaly proposed by @MensSana
Showing 1 changed file with 13 additions and 5 deletions   Show diff stats
app/controllers/projects/raw_controller.rb
@@ -11,11 +11,7 @@ class Projects::RawController < Projects::ApplicationController @@ -11,11 +11,7 @@ class Projects::RawController < Projects::ApplicationController
11 @blob = @repository.blob_at(@commit.id, @path) 11 @blob = @repository.blob_at(@commit.id, @path)
12 12
13 if @blob 13 if @blob
14 - type = if @blob.mime_type =~ /html|javascript/  
15 - 'text/plain; charset=utf-8'  
16 - else  
17 - @blob.mime_type  
18 - end 14 + type = get_blob_type
19 15
20 headers['X-Content-Type-Options'] = 'nosniff' 16 headers['X-Content-Type-Options'] = 'nosniff'
21 17
@@ -29,5 +25,17 @@ class Projects::RawController < Projects::ApplicationController @@ -29,5 +25,17 @@ class Projects::RawController < Projects::ApplicationController
29 not_found! 25 not_found!
30 end 26 end
31 end 27 end
  28 +
  29 + private
  30 +
  31 + def get_blob_type
  32 + if @blob.mime_type =~ /html|javascript/
  33 + 'text/plain; charset=utf-8'
  34 + elsif @blob.name =~ /(?:msi|exe|rar|r0\d|7z|7zip|zip)$/
  35 + 'application/octet-stream'
  36 + else
  37 + @blob.mime_type
  38 + end
  39 + end
32 end 40 end
33 41