diff options
author | Mark Haines <mark.haines@matrix.org> | 2015-01-06 11:32:36 +0000 |
---|---|---|
committer | Mark Haines <mark.haines@matrix.org> | 2015-01-06 11:32:36 +0000 |
commit | 3c8c3bf3b781068637223d47d542d9d93a05a9b3 (patch) | |
tree | e33e66b2a4158dfc2fadc2bd1ab52df50ffafa05 /synapse/media/v1/base_resource.py | |
parent | spell out that VoIP needs TURN (diff) | |
download | synapse-3c8c3bf3b781068637223d47d542d9d93a05a9b3.tar.xz |
SYN-229: Include Content-Length when downloading files
Diffstat (limited to 'synapse/media/v1/base_resource.py')
-rw-r--r-- | synapse/media/v1/base_resource.py | 12 |
1 files changed, 10 insertions, 2 deletions
diff --git a/synapse/media/v1/base_resource.py b/synapse/media/v1/base_resource.py index 2f5440ab64..38e01970c0 100644 --- a/synapse/media/v1/base_resource.py +++ b/synapse/media/v1/base_resource.py @@ -201,7 +201,8 @@ class BaseMediaResource(Resource): defer.returnValue(media_info) @defer.inlineCallbacks - def _respond_with_file(self, request, media_type, file_path): + def _respond_with_file(self, request, media_type, file_path, + file_size=None): logger.debug("Responding with %r", file_path) if os.path.isfile(file_path): @@ -215,13 +216,20 @@ class BaseMediaResource(Resource): request.setHeader( b"Cache-Control", b"public,max-age=86400,s-maxage=86400" ) + if file_size is None: + stat = os.stat(file_path) + file_size = stat.st_size + + request.setHeader( + b"Content-Length", b"%d" % (file_size,) + ) with open(file_path, "rb") as f: yield FileSender().beginFileTransfer(f, request) request.finish() else: - self._respond_404() + self._respond_404(request) def _get_thumbnail_requirements(self, media_type): if media_type == "image/jpeg": |