diva: fix render_POST

This commit is contained in:
Hay1tsme 2024-01-12 12:18:23 -05:00
parent c6f2f7e0ef
commit 257b0dae87

View File

@ -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)