response: Add Conn and TLS methods
This commit is contained in:
parent
833edaf63d
commit
83c904913f
@ -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
|
||||
}
|
||||
|
19
response.go
19
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.
|
||||
//
|
||||
|
Loading…
Reference in New Issue
Block a user