{"record":{"id":"5835c9107da921db","repo":"can1357/oh-my-pi","slug":"request-body-too-large","errorCode":null,"errorMessage":"request body too large","messagePattern":"request body too large","errorType":"http","errorClass":"HTTPException","httpStatus":413,"severity":"error","filePath":"python/robomp/src/proxy/server.py","lineNumber":425,"sourceCode":"    async def _read_body_capped(request: Request) -> bytes:\n        \"\"\"Read the request body with a hard byte cap.\n\n        Checks `Content-Length` first (cheap reject before any read), then\n        streams chunks via `request.stream()` with a running counter so a\n        client that lies about (or omits) the header still can't get more\n        than `max_bytes` into memory. We deliberately do NOT call\n        `request.body()` first — that would buffer the full payload before\n        auth checks ever run.\n        \"\"\"\n        max_bytes = settings.gh_proxy_max_body_bytes\n        cl = request.headers.get(\"content-length\")\n        if cl is not None:\n            try:\n                declared = int(cl)\n            except ValueError as exc:\n                raise HTTPException(400, \"invalid content-length\") from exc\n            if declared > max_bytes:\n                raise HTTPException(status.HTTP_413_REQUEST_ENTITY_TOO_LARGE, \"request body too large\")\n        chunks: list[bytes] = []\n        total = 0\n        async for chunk in request.stream():\n            if not chunk:\n                continue\n            total += len(chunk)\n            if total > max_bytes:\n                raise HTTPException(status.HTTP_413_REQUEST_ENTITY_TOO_LARGE, \"request body too large\")\n            chunks.append(chunk)\n        body = b\"\".join(chunks)\n        # Starlette's `request.body()` / `request.json()` re-read from\n        # `request._body`. We consumed the stream above, so seed the cache\n        # to keep downstream JSON parsing working without a second read.\n        request._body = body  # type: ignore[attr-defined]\n        return body\n\n    async def _authenticate(request: Request) -> bytes:\n        body = await _read_body_capped(request)","sourceCodeStart":407,"sourceCodeEnd":443,"githubUrl":"https://github.com/can1357/oh-my-pi/blob/969062200754ea02cfac922e5ebb8c608c079e15/python/robomp/src/proxy/server.py#L407-L443","documentation":"When the declared Content-Length exceeds settings.gh_proxy_max_body_bytes, the proxy rejects the request up front with HTTP 413 'request body too large'. This is the header-based early check in _read_body_capped; a separate streaming check (errorIndex 3966) catches bodies whose actual size exceeds the cap.","triggerScenarios":"POSTing (e.g. post_comment, open_pull_request) with a JSON body whose Content-Length header is larger than gh_proxy_max_body_bytes.","commonSituations":"Attaching huge payloads by mistake (embedding file contents in a comment); a batch script concatenating many items into one request; misconfigured gateway forwarding compressed+uncompressed duplicates; too-low server limit for legitimate payloads.","solutions":["Shrink the request payload (split into multiple smaller calls, truncate embedded content)","If the limit is genuinely too small, raise gh_proxy_max_body_bytes in the proxy settings","Compress content externally (e.g. paste a link instead of inlining large text)"],"exampleFix":"// before\nawait post(\"/gh/v1/post_comment\", { body: hugeText });\n// after\nconst summary = hugeText.slice(0, 5000);\nawait post(\"/gh/v1/post_comment\", { body: summary });","handlingStrategy":"validation","validationCode":"const MAX = settings.gh_proxy_max_body_bytes; // obtain configured limit\nif (Buffer.byteLength(payload) > MAX) throw new Error(`body ${Buffer.byteLength(payload)}B exceeds ${MAX}B cap`);","typeGuard":null,"tryCatchPattern":"try {\n  const res = await fetch(url, opts);\n  if (res.status === 413) throw new Error(\"request body too large: split or shrink the payload\");\n} catch (err) { /* handle */ }","preventionTips":["Check payload size before every write call","Split large content into multiple requests","Know the configured gh_proxy_max_body_bytes and enforce it client-side"],"tags":["http-413","payload-size","rate-limit-style"],"backgroundTag":"request-body-too-large","analyzedSha":"969062200754ea02cfac922e5ebb8c608c079e15","analyzedAt":"2026-08-31T10:29:35.737Z","schemaVersion":2},"datasetVersion":"2026-08-31T14:17:45.589Z"}