siyuan-note/siyuan · error
response too large
Error message
response too large
What it means
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.
Source
Thrown at kernel/util/httprequest.go:104
resp, err := sendByMethod(request, method, rawURL)
if err != nil {
return 0, "", "", errors.New("request failed: " + err.Error())
}
if resp == nil {
return 0, "", "", errors.New("nil response")
}
defer resp.Body.Close()
statusCode = resp.StatusCode
contentType = resp.Header.Get("Content-Type")
maxReadBytes := int64(maxHTTPRequestBytes)
if !isTextContentType(contentType) {
maxReadBytes = maxHTTPRequestFileBytes
}
// ContentLength 为 -1(chunked)时跳过大小预检,交由 LimitReader 兜底截断。
if resp.ContentLength > maxReadBytes {
return statusCode, contentType, "", errors.New("response too large")
}
respBody, rerr := io.ReadAll(io.LimitReader(resp.Body, maxReadBytes))
if rerr != nil {
return statusCode, contentType, "", errors.New("read body failed: " + rerr.Error())
}
// 二进制响应落盘,返回文件路径,供智能体按需进一步处理。
if !isTextContentType(contentType) {
importDir := filepath.Join(TempDir, "import")
if merr := os.MkdirAll(importDir, 0755); merr != nil {
return statusCode, contentType, "", errors.New("create import dir failed: " + merr.Error())
}
filename := extractFilename(rawURL, contentType)
filePath := filepath.Join(importDir, filename)
if werr := os.WriteFile(filePath, respBody, 0644); werr != nil {
return statusCode, contentType, "", errors.New("write file failed: " + werr.Error())
}View on GitHub (pinned to 251596fc0d)
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.
Example fix
// before
util.HTTPRequest("GET", "https://api.example.com/items", nil, "")
// after
util.HTTPRequest("GET", "https://api.example.com/items?page=1&per_page=50", nil, "") Defensive patterns
Strategy: validation
Prevention
- 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.
When it happens
Trigger: The remote server reports a Content-Length greater than maxHTTPRequestBytes (5 MiB text) or maxHTTPRequestFileBytes (10 MiB binary) in the response headers.
Common situations: 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.
Related errors
- URL must start with http:// or https://
- URL has no host
- Failed to update agent session permission
- missing query param [u]
- decode [u] failed: %s
AI-assisted analysis of siyuan-note/siyuan@251596fc0d (2026-08-12).
Data as JSON: /api/errors/c9ca0fc383b2d21d.
Report an issue: GitHub.