切换为默认的dns解析;增加resolver=system的支持

This commit is contained in:
wenyifan
2026-07-02 20:50:24 +08:00
parent a24d79fd45
commit bf85966600
6 changed files with 312 additions and 24 deletions
+14
View File
@@ -82,6 +82,11 @@ func NewExchanger(addr string, opts ...Option) (Exchanger, error) {
opt(&options)
}
addr = strings.TrimSpace(addr)
if isSystemResolverAddr(addr) {
return newSystemExchanger(addr, options), nil
}
if !strings.Contains(addr, "://") {
addr = "udp://" + addr
}
@@ -143,6 +148,15 @@ func NewExchanger(addr string, opts ...Option) (Exchanger, error) {
return ex, nil
}
func isSystemResolverAddr(addr string) bool {
switch strings.ToLower(strings.TrimSpace(addr)) {
case "system", "auto", "system://", "auto://":
return true
default:
return false
}
}
func (ex *exchanger) Exchange(ctx context.Context, msg []byte) ([]byte, error) {
if ex.network == "https" {
return ex.dohExchange(ctx, msg)