From 0e3ebac3627fe5039957d2d48d68d8620ff9384f Mon Sep 17 00:00:00 2001 From: Maxim Devaev Date: Sat, 23 Jul 2022 18:34:58 +0300 Subject: reading images api --- kvmd/htserver.py | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) (limited to 'kvmd/htserver.py') 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 -- cgit v1.2.3