summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMaxim Devaev <[email protected]>2021-07-26 02:29:47 +0300
committerMaxim Devaev <[email protected]>2021-07-26 02:29:52 +0300
commitc996771afd231d23c907c12b96fa2fff2fb1431a (patch)
tree0c49627a80bcd0fb46fd545f9b25293fa0ae1543
parent134d4e869e0cada9e69b2f37acf43606c5fddd3c (diff)
start_streaming()
-rw-r--r--kvmd/apps/kvmd/api/log.py4
-rw-r--r--kvmd/apps/kvmd/http.py6
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)