diff --git a/client.go b/client.go index 386cc7d..a9497c3 100644 --- a/client.go +++ b/client.go @@ -164,6 +164,7 @@ func (c *Client) do(ctx context.Context, conn net.Conn, req *Request) (*Response if err != nil { return nil, err } + resp.conn = conn return resp, nil } diff --git a/response.go b/response.go index 849e3f4..e091c1c 100644 --- a/response.go +++ b/response.go @@ -2,8 +2,10 @@ package gemini import ( "bufio" + "crypto/tls" "fmt" "io" + "net" "strconv" ) @@ -36,6 +38,8 @@ type Response struct { // a zero-length body. It is the caller's responsibility to // close Body. Body io.ReadCloser + + conn net.Conn } // ReadResponse reads a Gemini response from the provided io.ReadCloser. @@ -149,6 +153,21 @@ func (r *Response) Write(w io.Writer) error { return nil } +// Conn returns the network connection on which the response was received. +func (r *Response) Conn() net.Conn { + return r.conn +} + +// TLS returns information about the TLS connection on which the +// response was received. +func (r *Response) TLS() *tls.ConnectionState { + if tlsConn, ok := r.conn.(*tls.Conn); ok { + state := tlsConn.ConnectionState() + return &state + } + return nil +} + // A ResponseWriter interface is used by a Gemini handler to construct // a Gemini response. //