{"record":{"id":"acf76d54a1fe0d01","repo":"siyuan-note/siyuan","slug":"proxy-connect-returned-s","errorCode":null,"errorMessage":"proxy CONNECT returned %s","messagePattern":"proxy CONNECT returned (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"kernel/util/httprequest.go","lineNumber":248,"sourceCode":"\tif proxyURL.User != nil {\n\t\tpassword, _ := proxyURL.User.Password()\n\t\tcredentials := proxyURL.User.Username() + \":\" + password\n\t\tconnectReq.Header.Set(\"Proxy-Authorization\", \"Basic \"+base64.StdEncoding.EncodeToString([]byte(credentials)))\n\t}\n\tif err = connectReq.Write(conn); err != nil {\n\t\tconn.Close()\n\t\treturn nil, nil, err\n\t}\n\treader := bufio.NewReader(conn)\n\tresp, err := http.ReadResponse(reader, connectReq)\n\tif err != nil {\n\t\tconn.Close()\n\t\treturn nil, nil, err\n\t}\n\tif resp.StatusCode != http.StatusOK {\n\t\tresp.Body.Close()\n\t\tconn.Close()\n\t\treturn nil, nil, fmt.Errorf(\"proxy CONNECT returned %s\", resp.Status)\n\t}\n\treturn conn, reader, nil\n}\n\nfunc proxyAddress(proxyURL *url.URL) (string, error) {\n\tport := proxyURL.Port()\n\tif port == \"\" {\n\t\tswitch strings.ToLower(proxyURL.Scheme) {\n\t\tcase \"http\":\n\t\t\tport = \"80\"\n\t\tcase \"https\":\n\t\t\tport = \"443\"\n\t\tcase \"socks5\", \"socks5h\":\n\t\t\tport = \"1080\"\n\t\tdefault:\n\t\t\treturn \"\", errors.New(\"agent HTTP tools support HTTP, HTTPS and SOCKS5 proxies\")\n\t\t}\n\t}","sourceCodeStart":230,"sourceCodeEnd":266,"githubUrl":"https://github.com/siyuan-note/siyuan/blob/9f775e8a12daef8255556097396f9b2739078892/kernel/util/httprequest.go#L230-L266","documentation":"When tunneling through an HTTP(S) proxy, the transport sends an HTTP CONNECT request and requires a 200 response. Any other status from the proxy (403/407/502/504, etc.) closes the tunnel and surfaces the proxy's own status line in this error.","triggerScenarios":"Agent HTTP request via HTTP_PROXY/HTTPS_PROXY where the proxy answers CONNECT with a non-200: missing/wrong Proxy-Authorization credentials (407), proxy ACL blocking the target host or port (403), proxy cannot reach the target (502/504), proxy rejecting non-443 ports.","commonSituations":"Corporate proxy requiring per-user auth not embedded in the proxy URL; proxy allowlist not covering the target API domain; proxy refusing CONNECT to custom ports; proxy user/password changed or rotated; proxy has no internet egress.","solutions":["Read the status in the message: 407 means add correct credentials to the proxy URL (http://user:pass@proxy:port)","For 403, ask the proxy admin to allow-list the target host/port","For 502/504, verify the proxy itself can reach the target and retry later","Test the proxy directly: curl -x proxyURL targetURL","Remove HTTP_PROXY/HTTPS_PROXY if the proxy is not actually required"],"exampleFix":"// before: no credentials for auth proxy\n// HTTP_PROXY=http://proxy.corp.com:8080\n// after\n// HTTP_PROXY=http://user:pass@proxy.corp.com:8080","handlingStrategy":"retry","validationCode":null,"typeGuard":null,"tryCatchPattern":"if err != nil && strings.HasPrefix(err.Error(), \"proxy CONNECT returned \") {\n    status := strings.TrimPrefix(err.Error(), \"proxy CONNECT returned \")\n    switch {\n    case strings.HasPrefix(status, \"407\"):\n        // fix proxy credentials in the proxy URL\n    case strings.HasPrefix(status, \"403\"):\n        // target not allow-listed on the proxy\n    default:\n        // transient proxy failure: retry with backoff\n    }\n}","preventionTips":["Embed correct proxy credentials in the proxy URL (http://user:pass@proxy:port)","Ensure the proxy allow-list covers every target host and port used by agents","Smoke-test the proxy with curl -x before deploying agent workloads","Clear stale proxy env vars when no proxy is needed"],"tags":["proxy","connect","http-error-response","network"],"backgroundTag":"http-error-response","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"}