From dbcc8abdde2e78acd6bae7fe5cc095294193686b Mon Sep 17 00:00:00 2001 From: Pierre-Yves Chibon Date: Jul 04 2016 14:18:00 +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 7979977..2563bc4 100644 --- a/pagure/ui/repo.py +++ b/pagure/ui/repo.py @@ -545,16 +545,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