Export TLS & remove conn in request struct
This makes it possible to fully create another request outside of this module (which Hnakra will need) and has better parity with net/http.
This commit is contained in:
25
request.go
25
request.go
@@ -4,7 +4,6 @@ import (
|
||||
"bufio"
|
||||
"crypto/tls"
|
||||
"io"
|
||||
"net"
|
||||
"net/url"
|
||||
)
|
||||
|
||||
@@ -28,8 +27,7 @@ type Request struct {
|
||||
// This field is ignored by the Gemini server.
|
||||
Certificate *tls.Certificate
|
||||
|
||||
conn net.Conn
|
||||
tls *tls.ConnectionState
|
||||
TLS *tls.ConnectionState
|
||||
}
|
||||
|
||||
// NewRequest returns a new request.
|
||||
@@ -98,30 +96,11 @@ func (r *Request) WriteTo(w io.Writer) (int64, error) {
|
||||
return wrote, bw.Flush()
|
||||
}
|
||||
|
||||
// Conn returns the network connection on which the request was received.
|
||||
// Conn returns nil for client requests.
|
||||
func (r *Request) Conn() net.Conn {
|
||||
return r.conn
|
||||
}
|
||||
|
||||
// TLS returns information about the TLS connection on which the
|
||||
// request was received.
|
||||
// TLS returns nil for client requests.
|
||||
func (r *Request) TLS() *tls.ConnectionState {
|
||||
if r.tls == nil {
|
||||
if tlsConn, ok := r.conn.(*tls.Conn); ok {
|
||||
state := tlsConn.ConnectionState()
|
||||
r.tls = &state
|
||||
}
|
||||
}
|
||||
return r.tls
|
||||
}
|
||||
|
||||
// ServerName returns the value of the TLS Server Name Indication extension
|
||||
// sent by the client.
|
||||
// ServerName returns an empty string for client requests.
|
||||
func (r *Request) ServerName() string {
|
||||
if tls := r.TLS(); tls != nil {
|
||||
if tls := r.TLS; tls != nil {
|
||||
return tls.ServerName
|
||||
}
|
||||
return ""
|
||||
|
||||
Reference in New Issue
Block a user