Provide Handler with client remote address
This commit is contained in:
		
							parent
							
								
									39552c0f8f
								
							
						
					
					
						commit
						5a0a515874
					
				@ -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",
 | 
			
		||||
 | 
			
		||||
@ -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.
 | 
			
		||||
 | 
			
		||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user