Read the raw body from a framework request object. Tries the common attributes used by Flask (``get_data``/``data``), Django (``body``) and similar. Returns ``None`` when nothing usable is found so the caller surfaces a clear parse error.
(request: t.Any)
| 1379 | |
| 1380 | @staticmethod |
| 1381 | def _extract_request_body(request: t.Any) -> t.Union[str, bytes, None]: |
| 1382 | """Read the raw body from a framework request object. |
| 1383 | |
| 1384 | Tries the common attributes used by Flask (``get_data``/``data``), |
| 1385 | Django (``body``) and similar. Returns ``None`` when nothing usable is |
| 1386 | found so the caller surfaces a clear parse error. |
| 1387 | """ |
| 1388 | if request is None: |
| 1389 | return None |
| 1390 | |
| 1391 | # Flask: request.get_data() returns the raw body bytes. |
| 1392 | get_data = getattr(request, "get_data", None) |
| 1393 | if callable(get_data): |
| 1394 | return get_data() |
| 1395 | |
| 1396 | for attr in ("body", "data"): |
| 1397 | value = getattr(request, attr, None) |
| 1398 | if value is not None and not callable(value): |
| 1399 | return value |
| 1400 | |
| 1401 | return None |
| 1402 | |
| 1403 | @staticmethod |
| 1404 | def _body_to_str(body: t.Union[str, bytes, t.Mapping[str, t.Any], None]) -> str: |