DialContext doesn't give back TLS information
Dear devs,
thank you for providing this library, however, I have an issue:
I have an TLS encrypted connection, but the response of DialContext() doesn't provide this informations as resp.TLS is always nil. :(
Here I dial: https://salsa.debian.org/mdosch/xmpp-dns/-/blob/gorilla/main.go#L956 There it is always nil: https://salsa.debian.org/mdosch/xmpp-dns/-/blob/gorilla/main.go#L1007
Best regards, Martin
Use this function as a workaround for the missing functionality:
func getTLS(c any) *tls.ConnectionState {
for c != nil {
if tc, ok := c.(*tls.Conn); ok {
state := tc.ConnectionState()
return &state
}
wc, ok := c.(interface{ NetConn() net.Conn })
if !ok {
break
}
c = wc.NetConn()
}
return nil
}
Call it like this:
c, r, err := d.DialContext(...)
state := getTLS(c)
@tollwayclout thanks a lot, this works! :) How do you want to be attributed?
Thanks again. :)
See #967.