mirror of
https://github.com/moparisthebest/HttpUploadComponent
synced 2024-11-24 18:02:16 -05:00
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).
This commit is contained in:
parent
6d8993145b
commit
5ede0f9a7a
@ -8,16 +8,12 @@ import mimetypes
|
|||||||
import os
|
import os
|
||||||
import random
|
import random
|
||||||
import shutil
|
import shutil
|
||||||
import signal
|
|
||||||
import sleekxmpp
|
|
||||||
import ssl
|
import ssl
|
||||||
import string
|
import string
|
||||||
import sys
|
|
||||||
import yaml
|
import yaml
|
||||||
|
|
||||||
from sleekxmpp.componentxmpp import ComponentXMPP
|
from sleekxmpp.componentxmpp import ComponentXMPP
|
||||||
from threading import Lock
|
from threading import Lock
|
||||||
from threading import Thread
|
|
||||||
|
|
||||||
try:
|
try:
|
||||||
# Python 3
|
# Python 3
|
||||||
@ -150,6 +146,7 @@ class HttpHandler(BaseHTTPRequestHandler):
|
|||||||
if mime is None:
|
if mime is None:
|
||||||
mime = 'application/octet-stream'
|
mime = 'application/octet-stream'
|
||||||
self.send_header("Content-Type", mime)
|
self.send_header("Content-Type", mime)
|
||||||
|
if mime[:6] != 'image/':
|
||||||
self.send_header("Content-Disposition", 'attachment; filename="{}"'.format(os.path.basename(filename)))
|
self.send_header("Content-Disposition", 'attachment; filename="{}"'.format(os.path.basename(filename)))
|
||||||
fs = os.fstat(f.fileno())
|
fs = os.fstat(f.fileno())
|
||||||
self.send_header("Content-Length", str(fs.st_size))
|
self.send_header("Content-Length", str(fs.st_size))
|
||||||
|
Loading…
Reference in New Issue
Block a user