{"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/8641553a1f07374001902d3ce773285db1292b2d/kernel/util/httprequest.go#L230-L266","documentation":"When connecting through an HTTP proxy, dialProxyTunnel sends a CONNECT request and requires HTTP 200. Any other status (403, 407, 502, 503...) is turned into 'proxy CONNECT returned <status>'. The proxy itself refused or failed the tunnel, so the raw status text is surfaced for diagnosis.","triggerScenarios":"RoundTrip through an HTTP/HTTPS proxy; the proxy responds to CONNECT with a non-200 status — auth rejected (407), destination blocked by proxy policy (403), proxy cannot reach the target (502/504), or proxy overloaded (503).","commonSituations":"Corporate proxy requiring credentials not supplied in the proxy URL; proxy ACL blocking the destination host/port; expired proxy credentials; target site blocked by company policy; proxy down or misconfigured upstream.","solutions":["Check the returned status: 407 → add credentials to the proxy URL (http://user:pass@proxy:port); 403 → destination blocked by proxy policy; 502/504 → proxy cannot reach the target","Verify proxy settings (env HTTP_PROXY/HTTPS_PROXY or app config) are correct and current","Test the same CONNECT with `curl -x <proxy> https://<target>` to isolate whether the proxy or the target is at fault","Ask the proxy administrator to allow the destination or fix the proxy"],"exampleFix":"// before\nproxy = \"http://proxy.corp:8080\"             // 407 Proxy Authentication Required\n// after\nproxy = \"http://user:secret@proxy.corp:8080\" // credentials supplied","handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"if _, _, err := dialProxyTunnel(ctx, proxyURL, targetAddr); err != nil {\n    var proxyErr *statusError\n    if strings.HasPrefix(err.Error(), \"proxy CONNECT returned \") {\n        code := strings.TrimPrefix(err.Error(), \"proxy CONNECT returned \")\n        // 407 → add credentials; 403 → proxy policy; 5xx → proxy upstream problem\n        _ = code\n    }\n    return err\n}","preventionTips":["Include credentials in the proxy URL when the proxy requires auth","Verify the proxy allows the destination host/port with curl -x first","Keep proxy config (env vars / app settings) current","Monitor proxy health; 5xx statuses usually mean the proxy cannot reach the target"],"tags":["proxy","http","network"],"backgroundTag":"http-error-response","analyzedSha":"8641553a1f07374001902d3ce773285db1292b2d","analyzedAt":"2026-09-11T16:08:28.414Z","contentChangedAt":"2026-09-11T16:08:28.414Z","schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}