feat(dns): default health HTTP port to 5554

Co-Authored-By: Virgil <virgil@lethean.io>
This commit is contained in:
Virgil 2026-04-03 23:08:14 +00:00
parent e89e8892de
commit 86fc04acdd
4 changed files with 28 additions and 2 deletions

View file

@ -64,6 +64,9 @@ func (service *Service) ServeHTTPHealth(bind string, port int) (*HealthServer, e
if bind == "" {
bind = "127.0.0.1"
}
if port <= 0 {
port = service.resolveHTTPPort()
}
address := net.JoinHostPort(bind, strconv.Itoa(port))
listener, err := net.Listen("tcp", address)

View file

@ -113,6 +113,13 @@ func (server *DNSServer) Close() error {
return err
}
func (service *Service) resolveHTTPPort() int {
if service == nil || service.httpPort <= 0 {
return DefaultHTTPPort
}
return service.httpPort
}
// Serve starts DNS over UDP and TCP.
//
// srv, err := service.Serve("0.0.0.0", 53)
@ -168,8 +175,8 @@ func (service *Service) ServeAll(bind string, dnsPort int, httpPort int) (*Servi
if dnsPort == 0 {
dnsPort = service.dnsPort
}
if httpPort == 0 {
httpPort = service.httpPort
if httpPort <= 0 {
httpPort = service.resolveHTTPPort()
}
dnsServer, err := service.Serve(bind, dnsPort)

View file

@ -19,6 +19,7 @@ import (
// fmt.Println(dns.DefaultTreeRootCheckInterval)
const DefaultTreeRootCheckInterval = 15 * time.Second
const DefaultDNSPort = 53
const DefaultHTTPPort = 5554
// NameRecords stores the cached DNS records for one name.
//

View file

@ -2250,6 +2250,21 @@ func TestServiceResolveServePortDefaultsToStandardDNSPort(t *testing.T) {
}
}
func TestServiceResolveHTTPPortDefaultsToStandardHTTPPort(t *testing.T) {
service := NewService(ServiceOptions{})
if service.resolveHTTPPort() != DefaultHTTPPort {
t.Fatalf("expected resolve HTTP port to default to %d, got %d", DefaultHTTPPort, service.resolveHTTPPort())
}
customPort := 5555
customService := NewService(ServiceOptions{
HTTPPort: customPort,
})
if customService.resolveHTTPPort() != customPort {
t.Fatalf("expected resolveHTTPPort to honor configured HTTPPort, got %d", customService.resolveHTTPPort())
}
}
func TestServiceActionNamesExposeAllRFCActions(t *testing.T) {
service := NewService(ServiceOptions{})