{"record":{"id":"c9ca0fc383b2d21d","repo":"siyuan-note/siyuan","slug":"response-too-large","errorCode":null,"errorMessage":"response too large","messagePattern":"response too large","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"kernel/util/httprequest.go","lineNumber":104,"sourceCode":"\tresp, err := sendByMethod(request, method, rawURL)\n\tif err != nil {\n\t\treturn 0, \"\", \"\", errors.New(\"request failed: \" + err.Error())\n\t}\n\tif resp == nil {\n\t\treturn 0, \"\", \"\", errors.New(\"nil response\")\n\t}\n\tdefer resp.Body.Close()\n\n\tstatusCode = resp.StatusCode\n\tcontentType = resp.Header.Get(\"Content-Type\")\n\n\tmaxReadBytes := int64(maxHTTPRequestBytes)\n\tif !isTextContentType(contentType) {\n\t\tmaxReadBytes = maxHTTPRequestFileBytes\n\t}\n\t// ContentLength 为 -1（chunked）时跳过大小预检，交由 LimitReader 兜底截断。\n\tif resp.ContentLength > maxReadBytes {\n\t\treturn statusCode, contentType, \"\", errors.New(\"response too large\")\n\t}\n\n\trespBody, rerr := io.ReadAll(io.LimitReader(resp.Body, maxReadBytes))\n\tif rerr != nil {\n\t\treturn statusCode, contentType, \"\", errors.New(\"read body failed: \" + rerr.Error())\n\t}\n\n\t// 二进制响应落盘，返回文件路径，供智能体按需进一步处理。\n\tif !isTextContentType(contentType) {\n\t\timportDir := filepath.Join(TempDir, \"import\")\n\t\tif merr := os.MkdirAll(importDir, 0755); merr != nil {\n\t\t\treturn statusCode, contentType, \"\", errors.New(\"create import dir failed: \" + merr.Error())\n\t\t}\n\t\tfilename := extractFilename(rawURL, contentType)\n\t\tfilePath := filepath.Join(importDir, filename)\n\t\tif werr := os.WriteFile(filePath, respBody, 0644); werr != nil {\n\t\t\treturn statusCode, contentType, \"\", errors.New(\"write file failed: \" + werr.Error())\n\t\t}","sourceCodeStart":86,"sourceCodeEnd":122,"githubUrl":"https://github.com/siyuan-note/siyuan/blob/251596fc0de2f9528c00c224252fd073a99973f4/kernel/util/httprequest.go#L86-L122","documentation":"Returned by HTTPRequest when resp.ContentLength (declared by the server, not -1) exceeds the cap: 5 MiB for text content types, 10 MiB for binary. The cap is chosen via isTextContentType(contentType). Responses with ContentLength -1 (chunked) skip this precheck and are bounded by LimitReader instead.","triggerScenarios":"The remote server reports a Content-Length greater than maxHTTPRequestBytes (5 MiB text) or maxHTTPRequestFileBytes (10 MiB binary) in the response headers.","commonSituations":"Fetching a large JSON/HTML dump, a big XML feed, or a binary asset (image, archive) that exceeds the cap; an endpoint that returns a full database export; paginating an API that ignores size parameters.","solutions":["Narrow the request: add pagination, range, or filter parameters so the response fits under the cap.","Use a different endpoint/path that returns a smaller representation (e.g. a summary instead of a full export).","If a larger binary is genuinely needed, fetch it via a path that is not bounded by the agent HTTP tool's caps."],"exampleFix":"// before\nutil.HTTPRequest(\"GET\", \"https://api.example.com/items\", nil, \"\")\n\n// after\nutil.HTTPRequest(\"GET\", \"https://api.example.com/items?page=1&per_page=50\", nil, \"\")","handlingStrategy":"validation","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":["Paginate or filter requests so responses stay under 5 MiB (text) / 10 MiB (binary).","Surface the cap to the agent/user so they narrow the request rather than hitting the limit."],"tags":["network","size-limit","http-request","validation"],"backgroundTag":null,"analyzedSha":"251596fc0de2f9528c00c224252fd073a99973f4","analyzedAt":"2026-08-12T21:18:37.123Z","schemaVersion":2},"datasetVersion":"2026-08-12T23:17:12.415Z"}