Update torrent download route headers (#298)

- Change disposition from inline to attachment
- Add Content-Length header (by updating `_get_cached_torrent_file`)
This commit is contained in:
Kfir Hadas 2017-07-20 11:00:20 +03:00 committed by Anna-Maria Meriniemi
parent 2e8e548067
commit fe4ac73ca2
1 changed files with 7 additions and 4 deletions

View File

@ -815,11 +815,14 @@ def download_torrent(torrent_id):
if not torrent or not torrent.has_torrent:
flask.abort(404)
resp = flask.Response(_get_cached_torrent_file(torrent))
resp.headers['Content-Type'] = 'application/x-bittorrent'
resp.headers['Content-Disposition'] = 'inline; filename="{0}"; filename*=UTF-8\'\'{0}'.format(
torrent_file, torrent_file_size = _get_cached_torrent_file(torrent)
disposition = 'attachment; filename="{0}"; filename*=UTF-8\'\'{0}'.format(
quote(torrent.torrent_name.encode('utf-8')))
resp = flask.Response(torrent_file)
resp.headers['Content-Type'] = 'application/x-bittorrent'
resp.headers['Content-Disposition'] = disposition
resp.headers['Content-Length'] = torrent_file_size
return resp
@ -922,7 +925,7 @@ def _get_cached_torrent_file(torrent):
with open(cached_torrent, 'wb') as out_file:
out_file.write(torrents.create_bencoded_torrent(torrent))
return open(cached_torrent, 'rb')
return open(cached_torrent, 'rb'), os.path.getsize(cached_torrent)
def get_serializer(secret_key=None):