about summary refs log tree commit diff
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.py12
1 files changed, 12 insertions, 0 deletions
diff --git a/gn_auth/auth/requests.py b/gn_auth/auth/requests.py
new file mode 100644
index 0000000..01ff765
--- /dev/null
+++ b/gn_auth/auth/requests.py
@@ -0,0 +1,12 @@
+"""Utilities to deal with requests."""
+from flask import request
+
+def request_json() -> dict:
+    """Retrieve the JSON sent in a request."""
+    if request.headers.get("Content-Type") == "application/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 request.json or {}
+    else:
+        return dict(request.args) or dict(request.form) or {}