From 070d63983fe5daef92005ea33d3b8c693c224c77 Mon Sep 17 00:00:00 2001 From: Pierre-Yves Chibon Date: Jul 04 2016 14:17:27 +0000 Subject: Avoid all html related mimetype and force the browser to download these files --- diff --git a/pagure/ui/repo.py b/pagure/ui/repo.py index f8e9489..c744810 100644 --- a/pagure/ui/repo.py +++ b/pagure/ui/repo.py @@ -636,16 +636,20 @@ def view_raw_file(repo, identifier, filename=None, username=None): if not mimetype and data[:2] == '#!': mimetype = 'text/plain' + headers = {} if not mimetype: if '\0' in data: mimetype = 'application/octet-stream' else: mimetype = 'text/plain' + elif 'html' in mimetype: + mimetype = 'application/octet-stream' + headers['Content-Disposition'] = 'attachment' if mimetype.startswith('text/') and not encoding: encoding = chardet.detect(ktc.to_bytes(data))['encoding'] - headers = {'Content-Type': mimetype} + headers['Content-Type'] = mimetype if encoding: headers['Content-Encoding'] = encoding