diff options
author | Lazlo Westerhof <github@lazlo.me> | 2014-08-10 10:44:06 +0200 |
---|---|---|
committer | Lazlo Westerhof <github@lazlo.me> | 2014-08-10 10:44:06 +0200 |
commit | a034b575ee75fb8b62ac17dc72192a0f6102def8 (patch) | |
tree | e2e53a8cf9f46552aa738007bec2f674fc3e319e | |
parent | e8cc7c3a4a4d89e8c481a70d0c046e7e393fc980 (diff) | |
download | onionshare-a034b575ee75fb8b62ac17dc72192a0f6102def8.tar.gz onionshare-a034b575ee75fb8b62ac17dc72192a0f6102def8.zip |
Guess the content type of a file
-rw-r--r-- | onionshare/onionshare.py | 6 |
1 files changed, 5 insertions, 1 deletions
diff --git a/onionshare/onionshare.py b/onionshare/onionshare.py index dc3dbf29..c699cfb1 100644 --- a/onionshare/onionshare.py +++ b/onionshare/onionshare.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -import os, sys, subprocess, time, hashlib, platform, json, locale, socket, argparse, Queue, inspect, base64 +import os, sys, subprocess, time, hashlib, platform, json, locale, socket, argparse, Queue, inspect, base64, mimetypes from random import randint from functools import wraps @@ -166,6 +166,10 @@ def download(slug_candidate): r = Response(generate()) r.headers.add('Content-Length', filesize) r.headers.add('Content-Disposition', 'attachment', filename=basename) + # guess content type + (content_type, _) = mimetypes.guess_type(basename, strict=False) + if content_type is not None: + r.headers.add('Content-Type', content_type) return r @app.errorhandler(404) |