From 5ede0f9a7a70912543755956f0bc79a15e7aeda8 Mon Sep 17 00:00:00 2001 From: Lars Bensmann Date: Sun, 26 Jul 2015 20:51:18 +0200 Subject: [PATCH] Just send Content-disposition: attachment-Header if content is no image Content-disposition: attachment prevents most code to be executed in the browser (Java being an exception), but this is not needed for images and makes viewing images in clients that don't show the pictures inline even more complicated. (Also this PR removes unused imports). --- server.py | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/server.py b/server.py index 319228e..3a186b8 100755 --- a/server.py +++ b/server.py @@ -8,16 +8,12 @@ import mimetypes import os import random import shutil -import signal -import sleekxmpp import ssl import string -import sys import yaml from sleekxmpp.componentxmpp import ComponentXMPP from threading import Lock -from threading import Thread try: # Python 3 @@ -150,7 +146,8 @@ class HttpHandler(BaseHTTPRequestHandler): if mime is None: mime = 'application/octet-stream' self.send_header("Content-Type", mime) - self.send_header("Content-Disposition", 'attachment; filename="{}"'.format(os.path.basename(filename))) + if mime[:6] != 'image/': + self.send_header("Content-Disposition", 'attachment; filename="{}"'.format(os.path.basename(filename))) fs = os.fstat(f.fileno()) self.send_header("Content-Length", str(fs.st_size)) self.end_headers() @@ -174,7 +171,7 @@ if __name__ == "__main__": parser = argparse.ArgumentParser() parser.add_argument("-c", "--config", default='config.yml', help='Specify alternate config file.') - parser.add_argument("-l", "--logfile", default=None, help='File where the server log will be stored. If not specified log to stdout.') + parser.add_argument("-l", "--logfile", default=None, help='File where the server log will be stored. If not specified log to stdout.') args = parser.parse_args() with open(args.config,'r') as ymlfile: