diff options
author | David Baker <dave@matrix.org> | 2015-01-13 13:15:51 +0000 |
---|---|---|
committer | David Baker <dave@matrix.org> | 2015-01-13 13:15:51 +0000 |
commit | c06a9063e1d838f776edfd79cfc8ab29c748d794 (patch) | |
tree | bcfa472e65d4dacbab666d5787eff9293e5ccc41 /synapse/media/v1/base_resource.py | |
parent | Split out function to decide whether to notify or a given event (diff) | |
parent | Merge branch 'hotfixes-v0.6.1b' of github.com:matrix-org/synapse into develop (diff) | |
download | synapse-c06a9063e1d838f776edfd79cfc8ab29c748d794.tar.xz |
Merge branch 'develop' into pushers
Diffstat (limited to 'synapse/media/v1/base_resource.py')
-rw-r--r-- | synapse/media/v1/base_resource.py | 15 |
1 files changed, 12 insertions, 3 deletions
diff --git a/synapse/media/v1/base_resource.py b/synapse/media/v1/base_resource.py index 2f5440ab64..688e7376ad 100644 --- a/synapse/media/v1/base_resource.py +++ b/synapse/media/v1/base_resource.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# Copyright 2014 OpenMarket Ltd +# Copyright 2014, 2015 OpenMarket Ltd # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -139,6 +139,7 @@ class BaseMediaResource(Resource): @download.addBoth def callback(media_info): del self.downloads[key] + return media_info return download @defer.inlineCallbacks @@ -201,7 +202,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 +217,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": |