diff options
-rw-r--r-- | kvmd/apps/kvmd/api/log.py | 4 | ||||
-rw-r--r-- | kvmd/apps/kvmd/http.py | 6 |
2 files changed, 8 insertions, 2 deletions
diff --git a/kvmd/apps/kvmd/api/log.py b/kvmd/apps/kvmd/api/log.py index 9c09d5bc..75e41471 100644 --- a/kvmd/apps/kvmd/api/log.py +++ b/kvmd/apps/kvmd/api/log.py @@ -29,6 +29,7 @@ from ....validators.kvm import valid_log_seek from ..logreader import LogReader from ..http import exposed_http +from ..http import start_streaming # ===== @@ -43,8 +44,7 @@ class LogApi: seek = valid_log_seek(request.query.get("seek", "0")) follow = valid_bool(request.query.get("follow", "false")) - response = StreamResponse(status=200, reason="OK", headers={"Content-Type": "text/plain"}) - await response.prepare(request) + response = await start_streaming(request, "text/plain") async for record in self.__log_reader.poll_log(seek, follow): await response.write(("[%s %s] --- %s" % ( diff --git a/kvmd/apps/kvmd/http.py b/kvmd/apps/kvmd/http.py index 941205b2..daa0452a 100644 --- a/kvmd/apps/kvmd/http.py +++ b/kvmd/apps/kvmd/http.py @@ -170,6 +170,12 @@ def make_json_exception(err: Exception, status: Optional[int]=None) -> aiohttp.w }, status=status) +async def start_streaming(request: aiohttp.web.Request, content_type: str) -> aiohttp.web.StreamResponse: + response = aiohttp.web.StreamResponse(status=200, reason="OK", headers={"Content-Type": content_type}) + await response.prepare(request) + return response + + # ===== async def get_field_value(reader: aiohttp.MultipartReader, name: str) -> str: field = await get_multipart_field(reader, name) |