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 {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
resp.conn = conn
|
||||||
|
|
||||||
return resp, nil
|
return resp, nil
|
||||||
}
|
}
|
||||||
|
19
response.go
19
response.go
@ -2,8 +2,10 @@ package gemini
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"bufio"
|
"bufio"
|
||||||
|
"crypto/tls"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
|
"net"
|
||||||
"strconv"
|
"strconv"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -36,6 +38,8 @@ type Response struct {
|
|||||||
// a zero-length body. It is the caller's responsibility to
|
// a zero-length body. It is the caller's responsibility to
|
||||||
// close Body.
|
// close Body.
|
||||||
Body io.ReadCloser
|
Body io.ReadCloser
|
||||||
|
|
||||||
|
conn net.Conn
|
||||||
}
|
}
|
||||||
|
|
||||||
// ReadResponse reads a Gemini response from the provided io.ReadCloser.
|
// ReadResponse reads a Gemini response from the provided io.ReadCloser.
|
||||||
@ -149,6 +153,21 @@ func (r *Response) Write(w io.Writer) error {
|
|||||||
return nil
|
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 ResponseWriter interface is used by a Gemini handler to construct
|
||||||
// a Gemini response.
|
// a Gemini response.
|
||||||
//
|
//
|
||||||
|
Loading…
Reference in New Issue
Block a user