(request: Request, secure: bool = False, as_dict: bool = False)
| 51 | |
| 52 | |
| 53 | def extract_body(request: Request, secure: bool = False, as_dict: bool = False) -> dict[str, Any] | str: |
| 54 | result: dict[str, Any] | str = {} if as_dict else "" |
| 55 | if not hasattr(request.state, "body"): |
| 56 | return result |
| 57 | body = request.state.body |
| 58 | if not body: |
| 59 | return result |
| 60 | body_request = body.decode("utf-8", errors="ignore") |
| 61 | try: |
| 62 | result = json.loads(body_request) |
| 63 | if secure: |
| 64 | result = filter_params(result) |
| 65 | if not as_dict: |
| 66 | result = json.dumps(result, ensure_ascii=False, indent=2) |
| 67 | except json.JSONDecodeError: |
| 68 | pass |
| 69 | |
| 70 | return result |
no test coverage detected