From fcadd6383c917d5a00ca191dfa7bbfb58a6a83fe Mon Sep 17 00:00:00 2001 From: blank X Date: Fri, 21 May 2021 17:01:05 +0700 Subject: [PATCH] Add support for modifying Content-Type --- streamtg.py | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/streamtg.py b/streamtg.py index 04fec8f..c01db8b 100644 --- a/streamtg.py +++ b/streamtg.py @@ -111,6 +111,13 @@ async def handler(request): ) status = 206 length = end - offset + 1 + headers = { + 'Content-Range': f'bytes {offset}-{end}/{max_size}', + 'Content-Length': str(length), + 'Accept-Ranges': 'bytes' + } + if content_type := requests.headers.get('Content-Type'): + headers['Content-Type'] = content_type async def download(): tmp_offset = offset @@ -131,11 +138,7 @@ async def handler(request): return web.Response(status=status, body=download(), - headers={ - 'Content-Range': f'bytes {offset}-{end}/{max_size}', - 'Content-Length': str(length), - 'Accept-Ranges': 'bytes' - } + headers=headers ) app = web.Application()