{"id":"252df1873f8ba18d","repo":"aio-libs/aiohttp","slug":"got-more-than-limit-bytes-when-reading-line-r","errorCode":null,"errorMessage":"Got more than {limit} bytes when reading: {line!r}.","messagePattern":"Got more than (.+?) bytes when reading: (.+?)\\.","errorType":"http","errorClass":"LineTooLong","httpStatus":400,"severity":"error","filePath":"aiohttp/http_parser.py","lineNumber":210,"sourceCode":"            if not TOKENRE.fullmatch(name):\n                raise InvalidHeader(bname)\n\n            # next line\n            lines_idx += 1\n            line = lines[lines_idx]\n\n            # consume continuation lines\n            continuation = self._lax and line and line[0] in (32, 9)  # (' ', '\\t')\n\n            # Deprecated: https://www.rfc-editor.org/rfc/rfc9112.html#name-obsolete-line-folding\n            if continuation:\n                header_length = len(bvalue)\n                bvalue_lst = [bvalue]\n                while continuation:\n                    header_length += len(line)\n                    if header_length > self.max_field_size:\n                        header_line = bname + b\": \" + b\"\".join(bvalue_lst)\n                        raise LineTooLong(\n                            header_line[:100] + b\"...\", self.max_field_size\n                        )\n                    bvalue_lst.append(line)\n\n                    # next line\n                    lines_idx += 1\n                    if lines_idx < line_count:\n                        line = lines[lines_idx]\n                        if line:\n                            continuation = line[0] in (32, 9)  # (' ', '\\t')\n                    else:\n                        line = b\"\"\n                        break\n                bvalue = b\"\".join(bvalue_lst)\n\n            bvalue = bvalue.strip(b\" \\t\")\n            value = bvalue.decode(\"utf-8\", \"surrogateescape\")\n","sourceCodeStart":192,"sourceCodeEnd":228,"githubUrl":"https://github.com/aio-libs/aiohttp/blob/c0ef574e29109210e96e652771ae4e7b88615fa4/aiohttp/http_parser.py#L192-L228","documentation":"Raised by HeadersParser.parse_headers (aiohttp/http_parser.py:210) only in lax mode while accumulating obsolete line-folding continuation lines (RFC 9112 section 5.2, deprecated since RFC 7230). If the running length of a folded header value plus its continuation lines exceeds max_field_size (default 8190), the parser aborts with LineTooLong. The strict request parser never processes continuation lines, so this is response-parser specific.","triggerScenarios":"An HTTP response whose header uses obsolete line folding (a continuation line beginning with space or tab) and whose folded value is longer than max_field_size bytes. Only the lax HttpResponseParser (the default for responses) enters the continuation loop.","commonSituations":"Legacy servers that still fold long header values; very large Set-Cookie or WWW-Authenticate values that some intermediary folds across lines; or non-compliant gateways.","solutions":["Raise max_field_size when constructing the response parser / ClientSession if the upstream legitimately sends large folded headers.","If you control the server, send single-line header values instead of relying on deprecated line folding.","If you cannot change the upstream, treat the response as unrecoverable and retry or fall back."],"exampleFix":"# before - default limit (8190) too small for upstream's folded header\nasync with aiohttp.ClientSession() as s:\n    async with s.get(url) as r:\n        ...\n# after - raise the field-size limit\nasync with aiohttp.ClientSession(\n    response_class=lambda *a, **kw: aiohttp.ClientResponse(*a, **kw)\n) as s:\n    ...  # configure max_field_size via a custom protocol/parser if needed,\n         # or filter at the proxy layer","handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"from aiohttp import http_exceptions\ntry:\n    async with session.get(url) as resp:\n        body = await resp.read()\nexcept http_exceptions.LineTooLong as e:\n    log.warning(\"upstream folded header too long (limit=%d)\", e.args[1])\n    raise","preventionTips":["Tune max_field_size to match your upstream's largest folded header","Avoid obsolete line folding in responses you generate","Front legacy servers with a proxy that unfolds long headers"],"tags":["http","headers","parser","limits","response","configuration"],"analyzedSha":"c0ef574e29109210e96e652771ae4e7b88615fa4","analyzedAt":"2026-08-04T19:51:05.467Z","schemaVersion":2}