{"record":{"id":"310b06ca8268f0f8","repo":"Billionmail/BillionMail","slug":"base-url-must-use-http-or-https-protocol","errorCode":null,"errorMessage":"base URL must use http or https protocol","messagePattern":"base URL must use http or https protocol","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"core/internal/service/askai/supplier.go","lineNumber":493,"sourceCode":"\n// Testing validates the supplier's configuration by checking the base URL and API key.\n// It performs the following checks:\n// 1. Validates the base URL format.\n// 2. Tests the accessibility of the base URL by sending a HEAD request.\n// 3. Validates the API key by sending a GET request to the models endpoint.\n// If any of these checks fail, it returns an error indicating the issue.\nfunc Testing(supplierName, baseUrl, apiKey string) error {\n\tif supplierName == \"\" || baseUrl == \"\" || apiKey == \"\" {\n\t\treturn errors.New(\"supplier name, base URL, and API key are required\")\n\t}\n\n\t// Validate base URL format\n\tparsedUrl, err := url.ParseRequestURI(baseUrl)\n\tif err != nil {\n\t\treturn fmt.Errorf(\"invalid base URL format: %w\", err)\n\t}\n\tif parsedUrl.Scheme != \"http\" && parsedUrl.Scheme != \"https\" {\n\t\treturn errors.New(\"base URL must use http or https protocol\")\n\t}\n\t// Ensure the base URL ends with a slash\n\tif err := testBaseURLAccessibility(baseUrl); err != nil {\n\t\treturn fmt.Errorf(\"base URL accessibility test failed: %w\", err)\n\t}\n\t// Validate API key by making a request to the models endpoint\n\tif err := testAPIKeyValidity(baseUrl, apiKey); err != nil {\n\t\treturn fmt.Errorf(\"API key validation failed: %w\", err)\n\t}\n\n\treturn nil\n}\n\n// testBaseURLAccessibility checks if the base URL is accessible by sending a HEAD request.\n// It returns an error if the request fails or if the response status is not OK (200).\nfunc testBaseURLAccessibility(baseUrl string) error {\n\tclient := &http.Client{Timeout: 3 * time.Second}\n\tresp, err := client.Head(baseUrl)","sourceCodeStart":475,"sourceCodeEnd":511,"githubUrl":"https://github.com/Billionmail/BillionMail/blob/fc36c76c050c3775c5e899faf7403cf0262d2744/core/internal/service/askai/supplier.go#L475-L511","documentation":"After parsing succeeds, Testing requires the URL scheme to be exactly http or https. Any other scheme (ftp://, file://, ws://, etc.) is rejected with this error so that Testing never attempts HTTP requests against non-HTTP endpoints.","triggerScenarios":"Calling askai.Testing with a baseUrl whose scheme is not http/https, e.g. 'ftp://host', 'file:///path', or a URL that defaults to an unexpected scheme after parsing.","commonSituations":"Pasting a URL with a typo'd scheme (hhttps://, http:||); using a websocket-style endpoint; internal file URLs entered by mistake; scheme uppercase mismatch is fine (parsed scheme is lowercased) but a missing '//' can yield a different parse result.","solutions":["Prefix the endpoint with https:// (preferred) or http:// for local testing","Fix typos in the scheme (hhttps, httpss)","Use an HTTP(S) AI-compatible endpoint rather than other protocols"],"exampleFix":"// before\nerr := askai.Testing(name, \"ftp://files.example.com\", key)\n// after\nerr := askai.Testing(name, \"https://api.example.com/v1\", key)","handlingStrategy":"validation","validationCode":"func hasHTTPScheme(raw string) bool {\n    u, err := url.ParseRequestURI(strings.TrimSpace(raw))\n    return err == nil && (u.Scheme == \"http\" || u.Scheme == \"https\")\n}\nif !hasHTTPScheme(baseUrl) {\n    return errors.New(\"endpoint must start with http:// or https://\")\n}","typeGuard":null,"tryCatchPattern":"if err := askai.Testing(name, baseUrl, apiKey); err != nil {\n    if err.Error() == \"base URL must use http or https protocol\" {\n        return fmt.Errorf(\"unsupported protocol in %q; use http(s)\", baseUrl)\n    }\n    return err\n}","preventionTips":["Normalize/normalize-correct scheme typos (hhttps → https) on input","Restrict URL inputs to http/https in UI validation","Avoid passing non-HTTP endpoints (ftp, file, ws) to supplier Testing","Default to https:// when the user omits the scheme"],"tags":["go","validation","url","scheme"],"backgroundTag":"invalid-url-scheme","analyzedSha":"fc36c76c050c3775c5e899faf7403cf0262d2744","analyzedAt":"2026-09-05T21:28:54.019Z","contentChangedAt":"2026-09-05T21:28:54.019Z","schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}