mirror of
https://github.com/onionshare/onionshare.git
synced 2025-01-10 19:52:50 -03:00
Merge pull request #103 from lazlolazlolazlo/contenttype
Guess the content type of a file
This commit is contained in:
commit
c6a9fa01bd
1 changed files with 5 additions and 1 deletions
|
@ -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)
|
||||
|
|
Loading…
Reference in a new issue