{"record":{"id":"32f7afb495dcf12d","repo":"valyala/fasthttp","slug":"unsupported-protocol-q-http-and-https-are-suppor","errorCode":null,"errorMessage":"unsupported protocol %q. http and https are supported","messagePattern":"unsupported protocol %q\\. http and https are supported","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"client.go","lineNumber":557,"sourceCode":"// It is recommended obtaining req and resp via AcquireRequest\n// and AcquireResponse in performance-critical code.\nfunc (c *Client) Do(req *Request, resp *Response) error {\n\turi := req.URI()\n\tif uri == nil {\n\t\treturn ErrorInvalidURI\n\t}\n\n\thost := uri.Host()\n\n\tif bytes.ContainsRune(host, ',') {\n\t\treturn fmt.Errorf(\"invalid host %q: use a host client for multiple hosts\", host)\n\t}\n\n\tisTLS := false\n\tif uri.isHTTPS() {\n\t\tisTLS = true\n\t} else if !uri.isHTTP() {\n\t\treturn fmt.Errorf(\"unsupported protocol %q. http and https are supported\", uri.Scheme())\n\t}\n\n\tc.mOnce.Do(func() {\n\t\tc.m = make(map[string]*HostClient)\n\t\tc.ms = make(map[string]*HostClient)\n\t})\n\thc, err := c.hostClient(host, isTLS)\n\tif err != nil {\n\t\treturn err\n\t}\n\n\tatomic.AddInt32(&hc.pendingClientRequests, 1)\n\tdefer atomic.AddInt32(&hc.pendingClientRequests, -1)\n\treturn hc.Do(req, resp)\n}\n\nfunc (c *Client) hostClient(host []byte, isTLS bool) (*HostClient, error) {\n\tm := c.m","sourceCodeStart":539,"sourceCodeEnd":575,"githubUrl":"https://github.com/valyala/fasthttp/blob/c96f600972c6f4a7a30d664257b340ebe9d60124/client.go#L539-L575","documentation":"fasthttp's generic Client only supports http and https URI schemes when dispatching to HostClients. Any other scheme in the request URI causes this error before any connection is attempted.","triggerScenarios":"client.Do with a URI whose scheme is not http/https: \"ftp://...\", \"ws://...\", missing scheme handled incorrectly, or a URI built with a scheme variable set from config.","commonSituations":"Config-driven base URLs where users enter ws:// or no scheme, switching between grpc/websocket endpoints in shared HTTP code, typos like htp://.","solutions":["Change the URI to http:// or https://","For websockets/TCP use the appropriate library (websocket, net.Dial) instead of fasthttp.Client","Validate the scheme from config before constructing the request (req.URI().SetScheme or string check)","Normalize the base URL at startup: default missing schemes to http and reject unknown ones"],"exampleFix":"// before\nreq.SetRequestURI(baseURL + \"/path\") // baseURL = \"ftp://example.com\"\nclient.Do(req, resp)\n// after\nif !strings.HasPrefix(baseURL, \"http://\") && !strings.HasPrefix(baseURL, \"https://\") {\n    return fmt.Errorf(\"unsupported base URL scheme: %q\", baseURL)\n}\nreq.SetRequestURI(baseURL + \"/path\")","handlingStrategy":"validation","validationCode":"if !strings.HasPrefix(baseURL, \"http://\") && !strings.HasPrefix(baseURL, \"https://\") {\n    return fmt.Errorf(\"scheme must be http or https: %q\", baseURL)\n}","typeGuard":"func isHTTPScheme(u string) bool {\n    pu, err := url.Parse(u)\n    return err == nil && (pu.Scheme == \"http\" || pu.Scheme == \"https\")\n}","tryCatchPattern":"err := client.Do(req, resp)\nif err != nil {\n    if strings.Contains(err.Error(), \"unsupported protocol\") {\n        return fmt.Errorf(\"bad scheme in config: %w\", err)\n    }\n    return err\n}","preventionTips":["Normalize base URLs at startup: default to https, reject others","Route ws:// / ftp:// traffic to the correct client library","Validate scheme variables from config once, not per request"],"tags":["go","fasthttp","http-client","scheme"],"backgroundTag":"unsupported-protocol-scheme","analyzedSha":"c96f600972c6f4a7a30d664257b340ebe9d60124","analyzedAt":"2026-08-31T22:48:28.265Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T05:18:18.240Z"}