mirror of
https://git.sr.ht/~adnano/go-gemini
synced 2024-11-23 08:32:02 +01:00
Provide Handler with client remote address
This commit is contained in:
parent
4b96665150
commit
ec37cad3dd
@ -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…
Reference in New Issue
Block a user