From e67ef7d790313e2fda3551363e315ddcf49bd316 Mon Sep 17 00:00:00 2001 From: 0880 <98263509+0880880@users.noreply.github.com> Date: Tue, 20 Jan 2026 20:20:20 +0330 Subject: [PATCH] Add json() method for parsing request --- slow/slow.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/slow/slow.py b/slow/slow.py index 5e1a130..ba32f95 100644 --- a/slow/slow.py +++ b/slow/slow.py @@ -3,6 +3,7 @@ import http.client import json import re import urllib.parse +from json.decoder import JSONDecodeError from pathlib import Path from typing import Any, Awaitable, Callable, Optional @@ -57,6 +58,11 @@ class Request: } ) + def json(self) -> dict | None: + try: + return json.loads(self.body) + except JSONDecodeError: + return None async def _default_404_route(request: Request): return "HTTP/1.1 404 Not Found\r\nContent-Type: text/html\r\n\r\n404 Not Found contact admin".encode(