aboutsummaryrefslogtreecommitdiff
path: root/gn_auth/auth/requests.py
diff options
context:
space:
mode:
Diffstat (limited to 'gn_auth/auth/requests.py')
-rw-r--r--gn_auth/auth/requests.py10
1 files changed, 9 insertions, 1 deletions
diff --git a/gn_auth/auth/requests.py b/gn_auth/auth/requests.py
index 00e9b35..cd939dd 100644
--- a/gn_auth/auth/requests.py
+++ b/gn_auth/auth/requests.py
@@ -1,6 +1,14 @@
"""Utilities to deal with requests."""
+import werkzeug
from flask import request
def request_json() -> dict:
"""Retrieve the JSON sent in a request."""
- return request.json or dict(request.form) or {}
+ try:
+ json_data = request.json
+ # KLUDGE: We have this check here since request.json has the
+ # type Any | None; see:
+ # <https://github.com/pallets/werkzeug/blob/7868bef5d978093a8baa0784464ebe5d775ae92a/src/werkzeug/wrappers/request.py#L545>
+ return json_data if isinstance(json_data, dict) else {}
+ except werkzeug.exceptions.UnsupportedMediaType:
+ return dict(request.form) or {}