Skip to content

Commit d051ef5

Browse files
committed
Made Request.json() available for PUT, PATCH and DELETE requests
1 parent 36dc073 commit d051ef5

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

adafruit_httpserver/request.py

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121

2222
from .headers import Headers
2323
from .interfaces import _IFieldStorage, _IXSSSafeFieldStorage
24+
from .methods import POST, PUT, PATCH, DELETE
2425

2526

2627
class QueryParams(_IXSSSafeFieldStorage):
@@ -410,8 +411,15 @@ def form_data(self) -> Union[FormData, None]:
410411
return self._form_data
411412

412413
def json(self) -> Union[dict, None]:
413-
"""Body of the request, as a JSON-decoded dictionary. Only available for POST requests."""
414-
return json.loads(self.body) if (self.body and self.method == "POST") else None
414+
"""
415+
Body of the request, as a JSON-decoded dictionary.
416+
Only available for POST, PUT, PATCH and DELETE requests.
417+
"""
418+
return (
419+
json.loads(self.body)
420+
if (self.body and self.method in (POST, PUT, PATCH, DELETE))
421+
else None
422+
)
415423

416424
@property
417425
def _raw_header_bytes(self) -> bytes:

0 commit comments

Comments
 (0)