siyuan-note/siyuan · error
proxy CONNECT returned
Error message
proxy CONNECT returned %s
What it means
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.
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
Example fix
// before: no credentials for auth proxy // HTTP_PROXY=http://proxy.corp.com:8080 // after // HTTP_PROXY=http://user:pass@proxy.corp.com:8080
Defensive patterns
Strategy: retry
Try / catch
if err != nil && strings.HasPrefix(err.Error(), "proxy CONNECT returned ") {
status := strings.TrimPrefix(err.Error(), "proxy CONNECT returned ")
switch {
case strings.HasPrefix(status, "407"):
// fix proxy credentials in the proxy URL
case strings.HasPrefix(status, "403"):
// target not allow-listed on the proxy
default:
// transient proxy failure: retry with backoff
}
} Prevention
- 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
When it happens
Trigger: 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.
Common situations: 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.
Understand the failure class
Background: "API error: {status}" and "HTTP 401/403/404/429/5xx" errors: non-2xx HTTP responses explained — this error's family across 27 libraries.
Related errors
- proxy returned unexpected tunnel data
- system proxy does not contain a supported HTTP, HTTPS or…
- access to private/internal IP is prohibited
- access to private/internal IP is prohibited
- agent HTTP tools support HTTP, HTTPS and SOCKS5 proxies
AI-assisted analysis of siyuan-note/siyuan@9f775e8a12 (2026-09-19).
Data as JSON: /api/errors/acf76d54a1fe0d01.
Report an issue: GitHub.
Appendix: source
Thrown at kernel/util/httprequest.go:248
if proxyURL.User != nil {
password, _ := proxyURL.User.Password()
credentials := proxyURL.User.Username() + ":" + password
connectReq.Header.Set("Proxy-Authorization", "Basic "+base64.StdEncoding.EncodeToString([]byte(credentials)))
}
if err = connectReq.Write(conn); err != nil {
conn.Close()
return nil, nil, err
}
reader := bufio.NewReader(conn)
resp, err := http.ReadResponse(reader, connectReq)
if err != nil {
conn.Close()
return nil, nil, err
}
if resp.StatusCode != http.StatusOK {
resp.Body.Close()
conn.Close()
return nil, nil, fmt.Errorf("proxy CONNECT returned %s", resp.Status)
}
return conn, reader, nil
}
func proxyAddress(proxyURL *url.URL) (string, error) {
port := proxyURL.Port()
if port == "" {
switch strings.ToLower(proxyURL.Scheme) {
case "http":
port = "80"
case "https":
port = "443"
case "socks5", "socks5h":
port = "1080"
default:
return "", errors.New("agent HTTP tools support HTTP, HTTPS and SOCKS5 proxies")
}
}View on GitHub (pinned to 9f775e8a12)