| 45 | return [content[index : index + size] for index in range(0, len(content), size)] |
| 46 | |
| 47 | |
| 48 | def _read_json(handler: BaseHTTPRequestHandler) -> Dict[str, Any]: |
| 49 | length = int(handler.headers.get("Content-Length") or 0) |
| 50 | if length <= 0: |
| 51 | return {} |
| 52 | raw = handler.rfile.read(length) |
| 53 | if not raw: |
| 54 | return {} |
| 55 | try: |
| 56 | parsed = json.loads(raw.decode("utf-8")) |
| 57 | except json.JSONDecodeError as exc: |
| 58 | raise ValueError(f"Invalid JSON body: {exc}") from exc |
| 59 | if not isinstance(parsed, dict): |
| 60 | raise ValueError("JSON body must be an object") |
| 61 | return parsed |
| 62 | |
| 63 | |