From b3db113b1b656ed6de36f643e44f10945f142da6 Mon Sep 17 00:00:00 2001 From: wwqgtxx Date: Wed, 13 Mar 2024 15:32:26 +0800 Subject: [PATCH] chore: allow disabled system hosts by environment variable `DISABLE_SYSTEM_HOSTS` --- component/resolver/host.go | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/component/resolver/host.go b/component/resolver/host.go index 69c29a3c..4a429629 100644 --- a/component/resolver/host.go +++ b/component/resolver/host.go @@ -3,6 +3,8 @@ package resolver import ( "errors" "net/netip" + "os" + "strconv" "strings" _ "unsafe" @@ -11,6 +13,8 @@ import ( "github.com/zhangyunhao116/fastrand" ) +var DisableSystemHosts, _ = strconv.ParseBool(os.Getenv("DISABLE_SYSTEM_HOSTS")) + type Hosts struct { *trie.DomainTrie[HostValue] } @@ -47,7 +51,7 @@ func (h *Hosts) Search(domain string, isDomain bool) (*HostValue, bool) { return &hostValue, false } - if !isDomain { + if !isDomain && !DisableSystemHosts { addr, _ := lookupStaticHost(domain) if hostValue, err := NewHostValue(addr); err == nil { return &hostValue, true