From 257b0dae87abf0aaa6b78cea03b3eef5109bc20c Mon Sep 17 00:00:00 2001 From: Hay1tsme Date: Fri, 12 Jan 2024 12:18:23 -0500 Subject: [PATCH] diva: fix render_POST --- titles/diva/index.py | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/titles/diva/index.py b/titles/diva/index.py index 15960ba..9dc17fe 100644 --- a/titles/diva/index.py +++ b/titles/diva/index.py @@ -79,12 +79,12 @@ class DivaServlet(BaseServlet): return True - def render_POST(self, request: Request, game_code: str, matchers: Dict) -> bytes: - req_raw = request.content.getvalue() - url_header = request.getAllHeaders() + async def render_POST(self, request: Request, game_code: str, matchers: Dict) -> bytes: + req_raw = await request.body() + url_header = request.headers # Ping Dispatch - if "THIS_STRING_SEPARATES" in str(url_header): + if "THIS_STRING_SEPARATES" in url_header: binary_request = req_raw.splitlines() binary_cmd_decoded = binary_request[3].decode("utf-8") url_data = binary_cmd_decoded # for logging @@ -103,13 +103,13 @@ class DivaServlet(BaseServlet): url_data = zlib.decompress(gz_string) # Decompressing the gzip except zlib.error as e: self.logger.error(f"Failed to defalte! {e} -> {gz_string}") - return b"stat=0" + return PlainTextResponse("stat=0") try: req_cls = BaseRequest(url_data) except DivaRequestParseException as e: self.logger.error(e) - return b"stat=0" + return PlainTextResponse("stat=0") self.logger.debug(f"Request: {url_data}\nHeaders: {url_header}") self.logger.info( @@ -120,7 +120,7 @@ class DivaServlet(BaseServlet): if not hasattr(self.base, handler_str): self.logger.warn(f"Unhandled cmd {req_cls.cmd}") - return BaseResponse(req_cls.cmd, req_cls.req_id).make().encode() + return PlainTextResponse(BaseResponse(req_cls.cmd, req_cls.req_id).make()) handler = getattr(self.base, handler_str) @@ -132,4 +132,4 @@ class DivaServlet(BaseServlet): response = f"cmd={req_cls.cmd}&req_id={req_cls.req_id}&stat=ok" + response self.logger.debug(f"Response: {response}") - return response.encode(errors="ignore") + return PlainTextResponse(response)