diff --git a/response.go b/response.go index abbc757..57807e7 100644 --- a/response.go +++ b/response.go @@ -126,6 +126,7 @@ type ResponseWriter struct { mediatype string wroteHeader bool bodyAllowed bool + conn net.Conn } // NewResponseWriter returns a ResponseWriter that uses the provided io.WriteCloser. @@ -207,3 +208,17 @@ func (w *ResponseWriter) Flush() error { func (w *ResponseWriter) Close() error { return w.closer.Close() } + +// Conn returns the underlying network connection. +func (w *ResponseWriter) Conn() net.Conn { + return w.conn +} + +// TLS returns information about the underlying TLS connection. +func (w *ResponseWriter) TLS() *tls.ConnectionState { + if tlsConn, ok := w.conn.(*tls.Conn); ok { + state := tlsConn.ConnectionState() + return &state + } + return nil +} diff --git a/server.go b/server.go index 21634e2..dc327c6 100644 --- a/server.go +++ b/server.go @@ -360,6 +360,7 @@ func (srv *Server) serveConn(ctx context.Context, conn net.Conn) error { } w := NewResponseWriter(cw) + w.conn = conn req, err := ReadRequest(r) if err != nil {