ResponseWriter: Add TLS and Conn methods

This commit is contained in:
Adnan Maolood 2021-02-23 20:59:04 -05:00
parent 75abb99518
commit d35dd3d867
2 changed files with 16 additions and 0 deletions

View File

@ -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
}

View File

@ -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 {