diff --git a/request.go b/request.go index 1d9e1b4..e1ab914 100644 --- a/request.go +++ b/request.go @@ -23,9 +23,6 @@ type Request struct { // For international domain names, Host may be in Punycode or // Unicode form. Use golang.org/x/net/idna to convert it to // either format if needed. - // - // For server requests, Host specifies the host on which the URL - // is sought. Host string // For client requests, Certificate optionally specifies the @@ -33,20 +30,7 @@ type Request struct { // This field is ignored by the Gemini server. Certificate *tls.Certificate - // RemoteAddr allows Gemini servers and other software to record - // the network address that sent the request, usually for - // logging. This field is not filled in by ReadRequest. - // This field is ignored by the Gemini client. - RemoteAddr net.Addr - - // TLS allows Gemini servers and other software to record - // information about the TLS connection on which the request - // was received. This field is not filled in by ReadRequest. - // The Gemini server in this package sets the field for - // TLS-enabled connections before invoking a handler; - // otherwise it leaves the field nil. - // This field is ignored by the Gemini client. - TLS *tls.ConnectionState + conn net.Conn } // NewRequest returns a new request. @@ -111,3 +95,18 @@ func (r *Request) Write(w io.Writer) error { } return bw.Flush() } + +// Conn returns the network connection on which the request was received. +func (r *Request) Conn() net.Conn { + return r.conn +} + +// TLS returns information about the TLS connection on which the +// response was received. +func (r *Request) TLS() *tls.ConnectionState { + if tlsConn, ok := r.conn.(*tls.Conn); ok { + state := tlsConn.ConnectionState() + return &state + } + return nil +} diff --git a/server.go b/server.go index d577c97..b5c61cf 100644 --- a/server.go +++ b/server.go @@ -366,16 +366,7 @@ func (srv *Server) serveConn(ctx context.Context, conn net.Conn) error { w.WriteHeader(StatusBadRequest, "Bad request") return w.Flush() } - - // Store the TLS connection state - if tlsConn, ok := conn.(*tls.Conn); ok { - state := tlsConn.ConnectionState() - req.TLS = &state - req.Host = state.ServerName - } - - // Store remote address - req.RemoteAddr = conn.RemoteAddr() + req.conn = conn h := srv.Handler if h == nil {