{"id":"106fb3c8f02c32c2","repo":"gofiber/fiber","slug":"client-invalid-proxy-url-w","errorCode":null,"errorMessage":"client: invalid proxy URL: %w","messagePattern":"client: invalid proxy URL: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"client/client.go","lineNumber":369,"sourceCode":"\t\tc.logger.Panicf(\"client: %v\", ErrFailedToAppendCert)\n\t}\n\n\treturn c\n}\n\n// SetProxyURL sets the proxy URL for the client. This affects all subsequent requests.\nfunc (c *Client) SetProxyURL(proxyURL string) error {\n\tc.mu.Lock()\n\tdefer c.mu.Unlock()\n\n\t// Build the fasthttp proxy dialer directly so invalid proxy URLs are returned\n\t// to callers instead of being swallowed by FasthttpHTTPDialer.\n\tdialer := fasthttpproxy.Dialer{\n\t\tConfig: httpproxy.Config{HTTPProxy: proxyURL, HTTPSProxy: proxyURL},\n\t}\n\tdialFunc, err := dialer.GetDialFunc(false)\n\tif err != nil {\n\t\treturn fmt.Errorf(\"client: invalid proxy URL: %w\", err)\n\t}\n\tc.applyDial(dialFunc)\n\treturn nil\n}\n\n// RetryConfig returns a copy of the current retry configuration.\nfunc (c *Client) RetryConfig() *RetryConfig {\n\tc.mu.RLock()\n\tdefer c.mu.RUnlock()\n\n\tif c.retryConfig == nil {\n\t\treturn nil\n\t}\n\n\tcfg := *c.retryConfig\n\treturn &cfg\n}\n","sourceCodeStart":351,"sourceCodeEnd":387,"githubUrl":"https://github.com/gofiber/fiber/blob/9a4c7e57fe0b080a04235d28a4b0d2b4b353d58c/client/client.go#L351-L387","documentation":"Returned by Client.SetProxyURL (client/client.go:369) when the fasthttpproxy dialer cannot build a dial function from the supplied proxy URL. The client builds a fasthttpproxy.Dialer with the URL as both HTTPProxy and HTTPSProxy and calls GetDialFunc; if that returns an error it is wrapped and returned to the caller instead of being silently swallowed later by the fasthttp dialer. Supported schemes are the ones fasthttpproxy understands (http, https, socks5, socks5h); anything else fails here.","triggerScenarios":"Calling client.SetProxyURL(\"ftp://127.0.0.1:8080\") (the test-suite reproducer), passing a URL with an unsupported scheme, a malformed URL (missing host, unparseable), or SOCKS credentials that fasthttpproxy rejects. Also triggered by reading the proxy from an env var that is empty or corrupt.","commonSituations":"Reading HTTP_PROXY/HTTPS_PROXY from the environment and passing it unchecked; a typo in the scheme (fttp://, htt://); pasting a proxy address without a scheme; rotating to a SOCKS proxy whose auth string is malformed; CI environment where the proxy var points at an internal scheme the library does not support.","solutions":["Check the error returned by SetProxyURL before issuing any requests and fail fast with the configured URL.","Use a supported scheme: http://, https://, socks5://, or socks5h:// — ftp:// and bare host:port are rejected.","Validate the proxy URL with net/url.Parse first and ensure Scheme and Host are non-empty before calling SetProxyURL.","Fall back to a direct connection (skip SetProxyURL) when the configured proxy is empty or known-invalid."],"exampleFix":"// before\n_ = client.SetProxyURL(proxyFromEnv) // error ignored\n\n// after — validate scheme, surface the error\nu, err := url.Parse(proxyFromEnv)\nif err != nil || u.Host == \"\" {\n    return fmt.Errorf(\"bad proxy URL %q: %w\", proxyFromEnv, err)\n}\nif err := client.SetProxyURL(proxyFromEnv); err != nil {\n    return fmt.Errorf(\"SetProxyURL: %w\", err)\n}","handlingStrategy":"validation","validationCode":"// Validate the proxy URL scheme/host before calling SetProxyURL.\nfunc validProxyURL(s string) error {\n    u, err := url.Parse(s)\n    if err != nil {\n        return err\n    }\n    switch u.Scheme {\n    case \"http\", \"https\", \"socks5\", \"socks5h\":\n    default:\n        return fmt.Errorf(\"unsupported proxy scheme %q\", u.Scheme)\n    }\n    if u.Host == \"\" {\n        return errors.New(\"proxy URL missing host\")\n    }\n    return nil\n}","typeGuard":null,"tryCatchPattern":"if err := client.SetProxyURL(proxy); err != nil {\n    log.Printf(\"proxy unusable, continuing direct: %v\", err)\n    // proceed without a proxy\n}","preventionTips":["Always check the error returned by SetProxyURL; never discard it.","Restrict schemes to http/https/socks5/socks5h.","Validate env-derived proxy URLs with net/url.Parse before use.","Fall back to a direct connection when the configured proxy is empty or invalid."],"tags":["client","proxy","config","network"],"analyzedSha":"9a4c7e57fe0b080a04235d28a4b0d2b4b353d58c","analyzedAt":"2026-08-04T21:44:03.395Z","schemaVersion":2}