From ec37cad3ddc447bf897cdade498e4bc98a512e52 Mon Sep 17 00:00:00 2001 From: adnano Date: Mon, 21 Sep 2020 20:44:10 -0400 Subject: [PATCH] Provide Handler with client remote address --- examples/server/server.go | 2 +- server.go | 9 +++++---- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/examples/server/server.go b/examples/server/server.go index 1040af9..155b1bd 100644 --- a/examples/server/server.go +++ b/examples/server/server.go @@ -27,7 +27,7 @@ func main() { mux := &gemini.Mux{} mux.HandleFunc("/", func(req *gemini.RequestInfo) *gemini.Response { - log.Printf("Request for %s with certificates %v", req.URL.String(), req.Certificates) + log.Printf("Request from %s for %s with certificates %v", req.RemoteAddr.String(), req.URL.String(), req.Certificates) return &gemini.Response{ Status: gemini.StatusSuccess, Meta: "text/gemini", diff --git a/server.go b/server.go index 134dfc2..4cd7f1e 100644 --- a/server.go +++ b/server.go @@ -102,10 +102,10 @@ func (s *Server) Serve(ln net.Listener) error { } // Gather information about the request - certs := rw.(*tls.Conn).ConnectionState().PeerCertificates reqInfo := &RequestInfo{ URL: url, - Certificates: certs, + Certificates: rw.(*tls.Conn).ConnectionState().PeerCertificates, + RemoteAddr: rw.RemoteAddr(), } resp := s.Handler.Serve(reqInfo) resp.Write(rw) @@ -115,8 +115,9 @@ func (s *Server) Serve(ln net.Listener) error { // RequestInfo contains information about a request. type RequestInfo struct { - URL *url.URL - Certificates []*x509.Certificate + URL *url.URL // the requested URL + Certificates []*x509.Certificate // client certificates + RemoteAddr net.Addr } // A Handler responds to a Gemini request.