Provide Handler with client remote address

This commit is contained in:
adnano 2020-09-21 20:44:10 -04:00
parent 39552c0f8f
commit 5a0a515874
2 changed files with 6 additions and 5 deletions

View File

@ -27,7 +27,7 @@ func main() {
mux := &gemini.Mux{} mux := &gemini.Mux{}
mux.HandleFunc("/", func(req *gemini.RequestInfo) *gemini.Response { 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{ return &gemini.Response{
Status: gemini.StatusSuccess, Status: gemini.StatusSuccess,
Meta: "text/gemini", Meta: "text/gemini",

View File

@ -102,10 +102,10 @@ func (s *Server) Serve(ln net.Listener) error {
} }
// Gather information about the request // Gather information about the request
certs := rw.(*tls.Conn).ConnectionState().PeerCertificates
reqInfo := &RequestInfo{ reqInfo := &RequestInfo{
URL: url, URL: url,
Certificates: certs, Certificates: rw.(*tls.Conn).ConnectionState().PeerCertificates,
RemoteAddr: rw.RemoteAddr(),
} }
resp := s.Handler.Serve(reqInfo) resp := s.Handler.Serve(reqInfo)
resp.Write(rw) resp.Write(rw)
@ -115,8 +115,9 @@ func (s *Server) Serve(ln net.Listener) error {
// RequestInfo contains information about a request. // RequestInfo contains information about a request.
type RequestInfo struct { type RequestInfo struct {
URL *url.URL URL *url.URL // the requested URL
Certificates []*x509.Certificate Certificates []*x509.Certificate // client certificates
RemoteAddr net.Addr
} }
// A Handler responds to a Gemini request. // A Handler responds to a Gemini request.