{"record":{"id":"4a647dc871b0596f","repo":"siyuan-note/siyuan","slug":"request-failed","errorCode":null,"errorMessage":"request failed: ","messagePattern":"request failed: ","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"kernel/util/httprequest.go","lineNumber":335,"sourceCode":"\tif method == \"\" {\n\t\tmethod = \"GET\"\n\t}\n\n\tvar reqBody io.Reader\n\tif body != \"\" && method != \"GET\" && method != \"HEAD\" {\n\t\treqBody = strings.NewReader(body)\n\t}\n\treq, err := http.NewRequest(method, rawURL, reqBody)\n\tif err != nil {\n\t\treturn 0, \"\", \"\", errors.New(\"invalid request: \" + err.Error())\n\t}\n\tfor k, v := range headers {\n\t\treq.Header.Set(k, v)\n\t}\n\n\tresp, err := ssrfSafeClient.Do(req)\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","sourceCodeStart":317,"sourceCodeEnd":353,"githubUrl":"https://github.com/siyuan-note/siyuan/blob/9f775e8a12daef8255556097396f9b2739078892/kernel/util/httprequest.go#L317-L353","documentation":"HTTPRequest wraps the Go net/http client (ssrfSafeClient) to fetch a URL for agent processing. This error is returned when the client's Do(req) call fails at the transport level, and the underlying error text is appended after the \"request failed: \" prefix. It means the HTTP round trip never produced a response: DNS failure, connection refused/reset, TLS handshake error, timeout, or an SSRF-guard rejection inside the custom transport.","triggerScenarios":"Calling HTTPRequest (via httpRequestHandler) with an unreachable host, a hostname that does not resolve, a closed port, a TLS certificate mismatch, a request context timeout/cancellation, or a URL blocked by the SSRF-safe client (private/loopback addresses, disallowed schemes).","commonSituations":"Typo in the target URL or hostname; the remote service is down or the port is wrong; the machine running SiYuan has no outbound network/DNS; self-signed or expired certificates; fetching http://127.0.0.1 or LAN addresses that the SSRF guard deliberately blocks; firewalls/proxies intercepting the connection.","solutions":["Read the appended underlying error text to identify the cause (no such host, connection refused, TLS, timeout) and fix accordingly","Verify the URL is correct, reachable (curl it from the same machine), and uses http/https with a valid port","If the target is a private/loopback address, move the resource to a publicly reachable endpoint — the SSRF-safe client intentionally blocks internal addresses","Check DNS resolution and outbound network/firewall/proxy configuration on the host","For TLS errors, fix the server certificate or install the needed CA; do not attempt to bypass the SSRF guard"],"exampleFix":"// before\nstatus, ctype, out, err := util.HTTPRequest(ctx, \"http://localhost:6806/api/x\")\n// after — use a reachable, public URL\nstatus, ctype, out, err := util.HTTPRequest(ctx, \"https://example.com/resource\")","handlingStrategy":"retry","validationCode":"u, err := url.Parse(target)\nif err != nil || (u.Scheme != \"http\" && u.Scheme != \"https\") { return fmt.Errorf(\"invalid URL\") }\nif host, _, e := net.SplitHostPort(u.Host); e == nil && (net.ParseIP(host).IsLoopback() || net.ParseIP(host).IsPrivate()) { return fmt.Errorf(\"SSRF guard will block private address\") }","typeGuard":null,"tryCatchPattern":"if err != nil && strings.HasPrefix(err.Error(), \"request failed:\") {\n    // inspect underlying cause; retry transient errors with backoff\n}","preventionTips":["Validate URLs (scheme + public reachability) before calling","Retry transient network errors with backoff","Monitor host DNS/firewall health","Never expect loopback/LAN URLs to work — the SSRF guard blocks them"],"tags":["network","http","ssrf","go"],"backgroundTag":"http-request-failed","analyzedSha":"9f775e8a12daef8255556097396f9b2739078892","analyzedAt":"2026-09-19T03:17:15.984Z","contentChangedAt":"2026-09-19T03:17:15.984Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}