aboutsummaryrefslogtreecommitdiff
path: root/gn_auth/auth/requests.py
blob: f577b9fc7bef07bff5ce055b8c7454a5f4e8a515 (about) (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
"""Utilities to deal with requests."""
import werkzeug
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 {}