1
0
mirror of https://git.sr.ht/~adnano/go-gemini synced 2024-09-21 08:21:33 +02:00

response: Add Conn and TLS methods

This commit is contained in:
Adnan Maolood 2021-02-23 16:36:17 -05:00
parent 833edaf63d
commit 83c904913f
2 changed files with 20 additions and 0 deletions

View File

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

View File

@ -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.
//