From 5537ac771d2bb02dd402aa223cfb7aafbc0690bd Mon Sep 17 00:00:00 2001 From: Miek Gieben Date: Sun, 12 May 2013 15:56:12 +0200 Subject: [PATCH] Recheck the server mux match logic And a test to make sure it all works. The root zone can still be configured as a last resort (wildcard) match. --- server.go | 6 ++---- server_test.go | 10 ++++++++++ 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/server.go b/server.go index f4ea2a58..4935e3c5 100644 --- a/server.go +++ b/server.go @@ -69,7 +69,7 @@ var DefaultServeMux = NewServeMux() var Authors = []string{"Miek Gieben", "Ask Bjørn Hansen", "Dave Cheney", "Dusty Wilson", "Peter van Dijk"} // Version holds the current version. -var Version = "v1.1" +var Version = "v1.2" // The HandlerFunc type is an adapter to allow the use of // ordinary functions as DNS handlers. If f is a function @@ -173,7 +173,6 @@ func (mux *ServeMux) match(q string, t uint16) Handler { lastbyte byte seendot bool = true ) - // TODO(mg): check for . for i := 0; i < len(q); i++ { if seendot { if h, ok := mux.z[q[lastdot+1:]]; ok { @@ -194,8 +193,7 @@ func (mux *ServeMux) match(q string, t uint16) Handler { } lastbyte = q[i] } - // Check for the root zone too, this only delays NXDOMAIN, because if we serve . it - // will be catched above. + // Wildcard match, if we have found nothing try the root zone as a last resort. if h, ok := mux.z["."]; ok { return h } diff --git a/server_test.go b/server_test.go index 0932567d..b6e93f51 100644 --- a/server_test.go +++ b/server_test.go @@ -96,3 +96,13 @@ func TestDotAsCatchAllWildcard(t *testing.T) { t.Error("boe. match failed") } } + +func TestRootServer(t *testing.T) { + mux := NewServeMux() + mux.Handle(".", HandlerFunc(HelloServer)) + + handler := mux.match(".", TypeNS) + if handler == nil { + t.Error("root match failed") + } +}