diff --git a/examples/auth.go b/examples/auth.go index 2a76612..e808afa 100644 --- a/examples/auth.go +++ b/examples/auth.go @@ -52,7 +52,7 @@ func fingerprint(cert *x509.Certificate) string { } func profile(ctx context.Context, w gemini.ResponseWriter, r *gemini.Request) { - tls := r.TLS() + tls := r.TLS if len(tls.PeerCertificates) == 0 { w.WriteHeader(gemini.StatusCertificateRequired, "Certificate required") return @@ -68,7 +68,7 @@ func profile(ctx context.Context, w gemini.ResponseWriter, r *gemini.Request) { } func changeUsername(ctx context.Context, w gemini.ResponseWriter, r *gemini.Request) { - tls := r.TLS() + tls := r.TLS if len(tls.PeerCertificates) == 0 { w.WriteHeader(gemini.StatusCertificateRequired, "Certificate required") return diff --git a/request.go b/request.go index 0613716..59bfb13 100644 --- a/request.go +++ b/request.go @@ -4,7 +4,6 @@ import ( "bufio" "crypto/tls" "io" - "net" "net/url" ) @@ -28,8 +27,7 @@ type Request struct { // This field is ignored by the Gemini server. Certificate *tls.Certificate - conn net.Conn - tls *tls.ConnectionState + TLS *tls.ConnectionState } // NewRequest returns a new request. @@ -98,30 +96,11 @@ func (r *Request) WriteTo(w io.Writer) (int64, error) { return wrote, bw.Flush() } -// Conn returns the network connection on which the request was received. -// Conn returns nil for client requests. -func (r *Request) Conn() net.Conn { - return r.conn -} - -// TLS returns information about the TLS connection on which the -// request was received. -// TLS returns nil for client requests. -func (r *Request) TLS() *tls.ConnectionState { - if r.tls == nil { - if tlsConn, ok := r.conn.(*tls.Conn); ok { - state := tlsConn.ConnectionState() - r.tls = &state - } - } - return r.tls -} - // ServerName returns the value of the TLS Server Name Indication extension // sent by the client. // ServerName returns an empty string for client requests. func (r *Request) ServerName() string { - if tls := r.TLS(); tls != nil { + if tls := r.TLS; tls != nil { return tls.ServerName } return "" diff --git a/server.go b/server.go index a8ff77b..766e849 100644 --- a/server.go +++ b/server.go @@ -371,7 +371,10 @@ func (srv *Server) goServeConn(ctx context.Context, conn net.Conn) error { w.WriteHeader(StatusBadRequest, "Bad request") return w.Flush() } - req.conn = conn + if tlsConn, ok := conn.(*tls.Conn); ok { + state := tlsConn.ConnectionState() + req.TLS = &state + } h := srv.Handler if h == nil {