diff options
Diffstat (limited to 'kvmd/apps')
-rw-r--r-- | kvmd/apps/kvmd/api/msd.py | 11 | ||||
-rw-r--r-- | kvmd/apps/kvmd/http.py | 24 |
2 files changed, 3 insertions, 32 deletions
diff --git a/kvmd/apps/kvmd/api/msd.py b/kvmd/apps/kvmd/api/msd.py index 4e1a7f14..1f1afd1e 100644 --- a/kvmd/apps/kvmd/api/msd.py +++ b/kvmd/apps/kvmd/api/msd.py @@ -48,9 +48,6 @@ from ..http import make_json_response from ..http import make_json_exception from ..http import start_streaming from ..http import stream_json -from ..http import get_multipart_reader -from ..http import get_multipart_reader_str -from ..http import get_multipart_reader_field # ====== @@ -86,15 +83,13 @@ class MsdApi: @exposed_http("POST", "/msd/write") async def __write_handler(self, request: Request) -> Response: - reader = await get_multipart_reader(request) - name = valid_msd_image_name(await get_multipart_reader_str(reader, "image")) - size = valid_int_f0(await get_multipart_reader_str(reader, "size")) - data_field = await get_multipart_reader_field(reader, "data") + name = valid_msd_image_name(request.query.get("image")) + size = valid_int_f0(request.content_length) written = 0 async with self.__msd.write_image(name, size) as chunk_size: while True: - chunk = await data_field.read_chunk(chunk_size) + chunk = await request.content.read(chunk_size) if not chunk: break written = await self.__msd.write_image_chunk(chunk) diff --git a/kvmd/apps/kvmd/http.py b/kvmd/apps/kvmd/http.py index ae2cebc0..0ecc1670 100644 --- a/kvmd/apps/kvmd/http.py +++ b/kvmd/apps/kvmd/http.py @@ -41,8 +41,6 @@ except ImportError: from ...logging import get_logger -from ...validators import ValidatorError - # ===== class HttpError(Exception): @@ -181,28 +179,6 @@ async def stream_json(response: aiohttp.web.StreamResponse, result: Dict) -> Non # ===== -async def get_multipart_reader(request: aiohttp.web.Request) -> aiohttp.MultipartReader: - try: - return (await request.multipart()) - except Exception: - raise ValidatorError("Expected multipart") - - -async def get_multipart_reader_str(reader: aiohttp.MultipartReader, name: str) -> str: - field = await get_multipart_reader_field(reader, name) - return (await field.read()).decode("utf-8") - - -async def get_multipart_reader_field(reader: aiohttp.MultipartReader, name: str) -> aiohttp.BodyPartReader: - field = await reader.next() - if not isinstance(field, aiohttp.BodyPartReader): - raise ValidatorError(f"Expected body part as {name!r} field") - if not field or field.name != name: - raise ValidatorError(f"Missing {name!r} field") - return field - - -# ===== _REQUEST_AUTH_INFO = "_kvmd_auth_info" |