summaryrefslogtreecommitdiff
path: root/kvmd/htserver.py
diff options
context:
space:
mode:
authorMaxim Devaev <[email protected]>2022-07-23 18:34:58 +0300
committerMaxim Devaev <[email protected]>2022-07-24 05:38:26 +0300
commit0e3ebac3627fe5039957d2d48d68d8620ff9384f (patch)
tree2792d2c261edffedf8bd8675f6ad8a5ea1bb56a3 /kvmd/htserver.py
parentde140537254a517559c78de048791a197011c1f6 (diff)
reading images api
Diffstat (limited to 'kvmd/htserver.py')
-rw-r--r--kvmd/htserver.py17
1 files changed, 15 insertions, 2 deletions
diff --git a/kvmd/htserver.py b/kvmd/htserver.py
index af4498c1..35f4b388 100644
--- a/kvmd/htserver.py
+++ b/kvmd/htserver.py
@@ -26,6 +26,7 @@ import asyncio
import contextlib
import dataclasses
import inspect
+import urllib.parse
import json
from typing import Tuple
@@ -187,8 +188,20 @@ def make_json_exception(err: Exception, status: Optional[int]=None) -> Response:
}, status=status)
-async def start_streaming(request: Request, content_type: str) -> StreamResponse:
- response = StreamResponse(status=200, reason="OK", headers={"Content-Type": content_type})
+async def start_streaming(
+ request: Request,
+ content_type: str,
+ content_length: int=-1,
+ file_name: str="",
+) -> StreamResponse:
+
+ response = StreamResponse(status=200, reason="OK")
+ response.content_type = content_type
+ if content_length >= 0:
+ response.content_length = content_length
+ if file_name:
+ file_name = urllib.parse.quote(file_name, safe="")
+ response.headers["Content-Disposition"] = f"attachment; filename*=UTF-8''{file_name}"
await response.prepare(request)
return response