diff options
author | Frederick Muriuki Muriithi | 2025-07-07 13:48:01 -0500 |
---|---|---|
committer | Frederick Muriuki Muriithi | 2025-07-07 13:48:01 -0500 |
commit | dcd9f3763b0dbb8c2b2d2571566ab4b3a02ccade (patch) | |
tree | 9ab1ebfc07f6c60b4d1d4f8007ea32168560486a | |
parent | c9a8efc34e405078876f41995f298ed5f7a1a688 (diff) | |
download | gn-auth-dcd9f3763b0dbb8c2b2d2571566ab4b3a02ccade.tar.gz |
Check "Content-Type" header. Also process get params.
* Use the "Content-Type" value to check whether or not to attempt to
read the sent values as json
* Process also the get parameter, to allow the endpoints to be
slightly more flexible (this probably breaks how HTTP should work).
-rw-r--r-- | gn_auth/auth/requests.py | 9 |
1 files changed, 4 insertions, 5 deletions
diff --git a/gn_auth/auth/requests.py b/gn_auth/auth/requests.py index cd939dd..f577b9f 100644 --- a/gn_auth/auth/requests.py +++ b/gn_auth/auth/requests.py @@ -4,11 +4,10 @@ from flask import request def request_json() -> dict: """Retrieve the JSON sent in a request.""" - try: - json_data = request.json + 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 json_data if isinstance(json_data, dict) else {} - except werkzeug.exceptions.UnsupportedMediaType: - return dict(request.form) or {} + return request.json or {} + else: + return dict(request.args) or dict(request.form) or {} |