Add json() method for parsing request
This commit is contained in:
@@ -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(
|
||||
|
||||
Reference in New Issue
Block a user