feat(ednsdiag): support custom DoH endpoint via --url

Allow overriding the provider preset with an explicit HTTPS DoH URL,
including validation that custom endpoints apply only to DoH queries.
This commit is contained in:
windyboy
2026-08-13 15:34:54 +08:00
parent 5b0f7950e6
commit 6f8a4918f0
3 changed files with 17 additions and 1 deletions
@@ -6,6 +6,7 @@ type QueryOptions struct {
Protocol string
Provider string
Method string
EndpointURL string
}
type Result struct {
@@ -3,6 +3,7 @@ package edns
import (
"context"
"fmt"
"net/url"
)
func Query(ctx context.Context, options QueryOptions) Result {
@@ -29,6 +30,18 @@ func Query(ctx context.Context, options QueryOptions) Result {
result.Error = &ErrorInfo{Class: "input", Message: err.Error()}
return result
}
if options.EndpointURL != "" {
if options.Protocol != "doh" {
result.Error = &ErrorInfo{Class: "input", Message: "custom --url applies only to DoH"}
return result
}
parsed, err := url.Parse(options.EndpointURL)
if err != nil || parsed.Scheme != "https" || parsed.Hostname() == "" {
result.Error = &ErrorInfo{Class: "input", Message: fmt.Sprintf("invalid DoH endpoint URL %q", options.EndpointURL)}
return result
}
provider = Provider{ID: "custom", Profile: "custom", DoHURL: options.EndpointURL}
}
result.Resolver = ResolverInfo{Provider: provider.ID, Profile: provider.Profile}
var response []byte