{"record":{"id":"283182d53016e774","repo":"Tencent/WeKnora","slug":"api-base-url-must-use-http-s-scheme-got-s","errorCode":null,"errorMessage":"api_base_url must use http(s):// scheme, got %s://","messagePattern":"api_base_url must use http\\(s\\):// scheme, got (.+?)://","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/im/feishu/adapter.go","lineNumber":103,"sourceCode":"\t\tencryptKey:        encryptKey,\n\t\tapiBaseURL:        apiBaseURL,\n\t}, nil\n}\n\n// validateAPIBaseURL checks that a custom Feishu/Lark API base URL uses an\n// http(s) scheme and passes SSRF validation. Empty or the region default is\n// allowed without further checks. Mirrors wecom.validateEndpointURL but allows\n// plain http for internal-network reverse proxies that terminate TLS at nginx.\nfunc validateAPIBaseURL(endpoint, defaultEndpoint string) error {\n\tif endpoint == \"\" || endpoint == defaultEndpoint {\n\t\treturn nil\n\t}\n\tu, err := url.Parse(endpoint)\n\tif err != nil {\n\t\treturn fmt.Errorf(\"invalid api_base_url: %w\", err)\n\t}\n\tif u.Scheme != \"http\" && u.Scheme != \"https\" {\n\t\treturn fmt.Errorf(\"api_base_url must use http(s):// scheme, got %s://\", u.Scheme)\n\t}\n\tif err := utils.ValidateURLForSSRF(endpoint); err != nil {\n\t\treturn fmt.Errorf(\"%w (for private deployments on internal networks, add the hostname to SSRF_WHITELIST)\", err)\n\t}\n\treturn nil\n}\n\n// api builds an Open Platform API URL on this adapter's cloud. path is a format\n// string beginning with \"/open-apis/\"; args fill its verbs.\nfunc (a *Adapter) api(path string, args ...any) string {\n\treturn a.apiBaseURL + fmt.Sprintf(path, args...)\n}\n\n// startStreamReaper starts a background goroutine (once) that periodically\n// removes orphaned stream entries from feishuStreams. This prevents memory\n// leaks when EndStream is never called due to panics or pipeline errors.\nfunc startStreamReaper() {\n\tstartReaperOnce.Do(func() {","sourceCodeStart":85,"sourceCodeEnd":121,"githubUrl":"https://github.com/Tencent/WeKnora/blob/988cbb03305e055d8ebb7d46d9ac6cc0803cd074/internal/im/feishu/adapter.go#L85-L121","documentation":"For a custom (non-default) Feishu api_base_url, the scheme must be http or https. validateAPIBaseURL returns this error verbatim (no wrap) when u.Scheme is anything else — including empty, meaning the URL had no scheme at all.","triggerScenarios":"NewAdapter with api_base_url like \"open.feishu.cn\" (no scheme), \"ftp://...\", or \"ws://...\" while the value differs from the default endpoint.","commonSituations":"Omitting https:// when typing the internal Feishu gateway address; using ws:// or grpc:// schemes by analogy with other SDKs; config examples copied without the scheme.","solutions":["Prefix the URL with https:// (or http:// for plaintext internal testing).","Remember the check only applies to custom endpoints — leaving api_base_url empty avoids it entirely.","If the scheme looks correct, check for leading whitespace which can make url.Parse yield an empty scheme."],"exampleFix":"// before\napi_base_url: \"feishu.internal.example.com\"\n// after\napi_base_url: \"https://feishu.internal.example.com\"","handlingStrategy":"validation","validationCode":"u, err := url.Parse(endpoint)\nif err == nil && u.Scheme != \"http\" && u.Scheme != \"https\" {\n    return fmt.Errorf(\"api_base_url must start with https:// (got %q)\", endpoint)\n}","typeGuard":"func hasHTTPScheme(s string) bool {\n    u, err := url.Parse(s)\n    return err == nil && (u.Scheme == \"http\" || u.Scheme == \"https\")\n}","tryCatchPattern":"if err := validateAPIBaseURL(endpoint, defaultEndpoint); err != nil {\n    if strings.Contains(err.Error(), \"must use http(s):// scheme\") {\n        return fmt.Errorf(\"prefix api_base_url with https://\")\n    }\n    return err\n}","preventionTips":["Always include the https:// scheme when configuring custom endpoints.","Normalize bare hostnames by prefixing https:// at config load time.","Only set api_base_url when targeting a genuinely different host.","Remember the empty scheme counts as invalid for custom endpoints."],"tags":["url","scheme","feishu"],"backgroundTag":"invalid-url-scheme","analyzedSha":"988cbb03305e055d8ebb7d46d9ac6cc0803cd074","analyzedAt":"2026-09-02T14:41:08.344Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}