From f4fcfa87937072f09cfe54ea7a7b59767bbffffc Mon Sep 17 00:00:00 2001 From: David Darrell Date: Thu, 4 Feb 2016 12:46:24 +0800 Subject: [PATCH 1/2] When the requested host is not found log the remote host. --- server/server.go | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/server/server.go b/server/server.go index 4fe12b36..12513e81 100644 --- a/server/server.go +++ b/server/server.go @@ -337,6 +337,12 @@ func (s *Server) ServeHTTP(w http.ResponseWriter, r *http.Request) { } } + // Get the remote host + remoteHost, _, err := net.SplitHostPort(r.RemoteAddr) + if err != nil { + remoteHost = r.RemoteAddr + } + if vh, ok := s.vhosts[host]; ok { status, _ := vh.stack.ServeHTTP(w, r) @@ -347,7 +353,7 @@ func (s *Server) ServeHTTP(w http.ResponseWriter, r *http.Request) { } else { w.WriteHeader(http.StatusNotFound) fmt.Fprintf(w, "No such host at %s", s.Server.Addr) - log.Printf("[INFO] %s - No such host at %s", host, s.Server.Addr) + log.Printf("[INFO] %s - No such host at %s (requested by %s)", host, s.Server.Addr, remoteHost) } } From 2acaf2fa6fa97b61ee0fa09e3eb8a5c782d6abf8 Mon Sep 17 00:00:00 2001 From: David Darrell Date: Thu, 4 Feb 2016 16:17:10 +0800 Subject: [PATCH 2/2] Move logic to split the port to only happen when the host is not found. --- server/server.go | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/server/server.go b/server/server.go index 12513e81..e325940d 100644 --- a/server/server.go +++ b/server/server.go @@ -337,12 +337,6 @@ func (s *Server) ServeHTTP(w http.ResponseWriter, r *http.Request) { } } - // Get the remote host - remoteHost, _, err := net.SplitHostPort(r.RemoteAddr) - if err != nil { - remoteHost = r.RemoteAddr - } - if vh, ok := s.vhosts[host]; ok { status, _ := vh.stack.ServeHTTP(w, r) @@ -351,6 +345,12 @@ func (s *Server) ServeHTTP(w http.ResponseWriter, r *http.Request) { DefaultErrorFunc(w, r, status) } } else { + // Get the remote host + remoteHost, _, err := net.SplitHostPort(r.RemoteAddr) + if err != nil { + remoteHost = r.RemoteAddr + } + w.WriteHeader(http.StatusNotFound) fmt.Fprintf(w, "No such host at %s", s.Server.Addr) log.Printf("[INFO] %s - No such host at %s (requested by %s)", host, s.Server.Addr, remoteHost)