summary refs log tree commit diff
path: root/synapse/rest/media/v1/base_resource.py
diff options
context:
space:
mode:
authorMark Haines <mark.haines@matrix.org>2015-08-26 16:26:37 +0100
committerMark Haines <mark.haines@matrix.org>2015-08-26 16:26:37 +0100
commite85c7873dc885c18705c2a77d8487517379d64fb (patch)
treec59c6030dc0347abea4963f2f11f7175e63ffe46 /synapse/rest/media/v1/base_resource.py
parentMerge pull request #252 from matrix-org/erikj/typing_loop (diff)
downloadsynapse-e85c7873dc885c18705c2a77d8487517379d64fb.tar.xz
Allow non-ascii filenames for attachments
Diffstat (limited to 'synapse/rest/media/v1/base_resource.py')
-rw-r--r--synapse/rest/media/v1/base_resource.py17
1 files changed, 13 insertions, 4 deletions
diff --git a/synapse/rest/media/v1/base_resource.py b/synapse/rest/media/v1/base_resource.py

index 4e21527c3d..24297b20f1 100644 --- a/synapse/rest/media/v1/base_resource.py +++ b/synapse/rest/media/v1/base_resource.py
@@ -33,6 +33,7 @@ import os import cgi import logging +import urllib logger = logging.getLogger(__name__) @@ -181,10 +182,18 @@ class BaseMediaResource(Resource): if os.path.isfile(file_path): request.setHeader(b"Content-Type", media_type.encode("UTF-8")) if upload_name: - request.setHeader( - b"Content-Disposition", - b"inline; filename=%s" % (upload_name.encode("utf-8"),), - ) + if is_ascii(upload_name): + request.setHeader( + b"Content-Disposition", + b"inline; filename=%s" % (upload_name.encode("utf-8"),), + ) + else: + request.setHeader( + b"Content-Disposition", + b"inline; filename*=utf-8''%s" % ( + urllib.quote(upload_name.encode("utf-8")), + ), + ) # cache for at least a day. # XXX: we might want to turn this off for data we don't want to