{"record":{"id":"45bb65c1231a6b98","repo":"ginuerzh/gost","slug":"failed-to-create-an-https-request-s","errorCode":null,"errorMessage":"failed to create an HTTPS request: %s","messagePattern":"failed to create an HTTPS request: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"resolver.go","lineNumber":894,"sourceCode":"\t\t\tExpectContinueTimeout: 1 * time.Second,\n\t\t\tDialContext:           ex.dialContext,\n\t\t},\n\t}\n\n\treturn ex\n}\n\nfunc (ex *dohExchanger) dialContext(ctx context.Context, network, address string) (net.Conn, error) {\n\treturn ex.options.chain.DialContext(ctx,\n\t\tnetwork, address,\n\t\tTimeoutChainOption(ex.options.timeout),\n\t)\n}\n\nfunc (ex *dohExchanger) Exchange(ctx context.Context, query []byte) ([]byte, error) {\n\treq, err := http.NewRequestWithContext(ctx, \"POST\", ex.endpoint.String(), bytes.NewBuffer(query))\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"failed to create an HTTPS request: %s\", err)\n\t}\n\n\t// req.Header.Add(\"Content-Type\", \"application/dns-udpwireformat\")\n\treq.Header.Add(\"Content-Type\", \"application/dns-message\")\n\treq.Host = ex.endpoint.Hostname()\n\n\tclient := ex.client\n\tif client == nil {\n\t\tclient = http.DefaultClient\n\t}\n\tresp, err := client.Do(req)\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"failed to perform an HTTPS request: %s\", err)\n\t}\n\n\t// Check response status code\n\tdefer resp.Body.Close()\n\tif resp.StatusCode != http.StatusOK {","sourceCodeStart":876,"sourceCodeEnd":912,"githubUrl":"https://github.com/ginuerzh/gost/blob/a33fdbf4c98034f4bfeeaea9868909822b9c526d/resolver.go#L876-L912","documentation":"dohExchanger.Exchange builds a POST request to a DNS-over-HTTPS endpoint with http.NewRequestWithContext (resolver.go:894). If constructing that request fails — most often because the DoH endpoint URL is invalid or cannot be parsed — the error is wrapped as \"failed to create an HTTPS request: %s\" and returned before any network activity. This is a setup error: the DNS query was never sent.","triggerScenarios":"A DoH exchanger created with a malformed endpoint URL (missing scheme, invalid characters, unparsable host) so http.NewRequestWithContext returns an error, e.g. a resolver config with a bad nameserver URL like \"dns.google/dns-query\" without \"https://\".","commonSituations":"Typos in the DoH URL in gost's resolver config, missing https:// scheme, control characters or spaces in the configured nameserver URL, or a config reload injecting an invalid endpoint string.","solutions":["Log the wrapped inner error (%s) to see the underlying url.Parse failure and fix the DoH endpoint string","Ensure the endpoint is a valid absolute https:// URL, e.g. https://dns.google/dns-query","Verify the resolver configuration (nameserver/DoH URL) has no stray spaces, quotes, or control characters","Pre-validate the URL with url.Parse in your config loader before wiring it into the resolver"],"exampleFix":"// before\nendpoint := \"dns.google/dns-query\" // invalid: no scheme\n// after\nendpoint := \"https://dns.google/dns-query\"","handlingStrategy":"validation","validationCode":"func validDoHEndpoint(raw string) error {\n    u, err := url.Parse(raw)\n    if err != nil { return fmt.Errorf(\"invalid DoH url %q: %w\", raw, err) }\n    if u.Scheme != \"https\" || u.Host == \"\" {\n        return fmt.Errorf(\"DoH endpoint must be an absolute https URL, got %q\", raw)\n    }\n    return nil\n}","typeGuard":"func isHTTPRequestCreateError(err error) bool {\n    return err != nil && strings.Contains(err.Error(), \"failed to create an HTTPS request\")\n}","tryCatchPattern":"resp, err := exchanger.Exchange(ctx, query)\nif err != nil {\n    if isHTTPRequestCreateError(err) {\n        log.Printf(\"check DoH endpoint config: %v\", err) // configuration bug, don't retry\n        return err\n    }\n    return failoverToNextNameserver(err) // network-level failures may fail over\n}","preventionTips":["Always configure DoH nameservers as absolute https:// URLs (e.g. https://dns.google/dns-query)","Trim spaces/quotes/control characters from the endpoint string when loading config","Validate with url.Parse in your config loader before constructing the resolver","Log the wrapped inner error so the underlying url.Parse reason is visible"],"tags":["dns","doh","http","network","gost"],"backgroundTag":"invalid-url","analyzedSha":"a33fdbf4c98034f4bfeeaea9868909822b9c526d","analyzedAt":"2026-09-02T22:15:54.506Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-10T02:17:09.455Z"}