{"record":{"id":"1b22160047977ec0","repo":"OtterMind/Chat2DB","slug":"request-body-is-too-large","errorCode":null,"errorMessage":"request body is too large","messagePattern":"request body is too large","errorType":"http","errorClass":"RequestError","httpStatus":413,"severity":"error","filePath":"script/github/qq_relay/relay_server.py","lineNumber":208,"sourceCode":"        self.end_headers()\n        self.wfile.write(body)\n\n    def _authorize(self) -> None:\n        expected = f\"Bearer {self.relay_state.config.relay_token}\"\n        supplied = self.headers.get(\"Authorization\", \"\")\n        if not hmac.compare_digest(supplied, expected):\n            raise RequestError(HTTPStatus.UNAUTHORIZED, \"unauthorized\")\n\n    def _read_payload(self) -> Mapping[str, Any]:\n        content_type = self.headers.get(\"Content-Type\", \"\")\n        if not content_type.lower().startswith(\"application/json\"):\n            raise RequestError(HTTPStatus.UNSUPPORTED_MEDIA_TYPE, \"Content-Type must be JSON\")\n        try:\n            content_length = int(self.headers.get(\"Content-Length\", \"\"))\n        except ValueError as error:\n            raise RequestError(HTTPStatus.LENGTH_REQUIRED, \"Content-Length is required\") from error\n        if content_length < 1 or content_length > MAX_REQUEST_BYTES:\n            raise RequestError(HTTPStatus.REQUEST_ENTITY_TOO_LARGE, \"request body is too large\")\n        try:\n            payload = json.loads(self.rfile.read(content_length).decode(\"utf-8\"))\n        except (UnicodeDecodeError, json.JSONDecodeError) as error:\n            raise RequestError(HTTPStatus.BAD_REQUEST, \"request body is not valid JSON\") from error\n        if not isinstance(payload, Mapping):\n            raise RequestError(HTTPStatus.BAD_REQUEST, \"request body must be a JSON object\")\n        return payload\n\n    def _validate_payload(self, payload: Mapping[str, Any]) -> tuple[str, str]:\n        config = self.relay_state.config\n        if payload.get(\"repository\") != config.repository:\n            raise RequestError(HTTPStatus.FORBIDDEN, \"repository is not allowed\")\n        delivery_id = payload.get(\"delivery_id\")\n        if not isinstance(delivery_id, str) or not DELIVERY_ID_PATTERN.fullmatch(delivery_id):\n            raise RequestError(HTTPStatus.BAD_REQUEST, \"delivery_id is invalid\")\n        message = payload.get(\"message\")\n        if not isinstance(message, str) or not message.strip():\n            raise RequestError(HTTPStatus.BAD_REQUEST, \"message must be non-empty text\")","sourceCodeStart":190,"sourceCodeEnd":226,"githubUrl":"https://github.com/OtterMind/Chat2DB/blob/5ee1e990e73fbcae1969dc554be254fedb3ab888/script/github/qq_relay/relay_server.py#L190-L226","documentation":"Raised by RelayHandler._read_payload (relay_server.py:208) as a RequestError(HTTP 413) when Content-Length is less than 1 or greater than MAX_REQUEST_BYTES (4096). The relay caps request size to protect memory; the bundled notifier's payload is well under this limit.","triggerScenarios":"A POST whose declared Content-Length is 0, negative, or exceeds 4096 bytes. An oversized message or an attempt to upload a large body triggers it.","commonSituations":"Sending a message longer than the limit; a client that adds large extra fields to the payload; a buggy client sending Content-Length far larger than the body; the notifier's message plus envelope approaching 4KB (the message itself is capped at 900 chars, so normally impossible from the notifier).","solutions":["Keep the total JSON request body under 4096 bytes.","Ensure the message field is within the 900-character cap and remove unneeded fields.","Verify Content-Length equals the actual body size."],"exampleFix":null,"handlingStrategy":"validation","validationCode":"MAX_REQUEST_BYTES = 4096\nbody_len = len(body)\nif body_len > MAX_REQUEST_BYTES:\n    raise SystemExit(f\"payload {body_len} bytes exceeds relay limit {MAX_REQUEST_BYTES}\")","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Keep the JSON request under 4096 bytes (message <= 900 chars helps).","Do not add large extra fields to the payload."],"tags":["http","relay","validation","limits"],"backgroundTag":null,"analyzedSha":"5ee1e990e73fbcae1969dc554be254fedb3ab888","analyzedAt":"2026-08-14T07:05:03.077Z","schemaVersion":2},"datasetVersion":"2026-08-14T10:17:34.591Z"}