I have a server net.Conn
, and I'd like to peek into it before reading out bytes, to check if it's a plain text protocol the client is trying to use, or SSL/TLS.
Checking http://golang.org/pkg/net/, it seems the Conn
interface does not have anything like that. I know I could use an iobuf.Reader
, but I'd like to get a TLS Conn via tls.Conn(conn, config)
if it turns out the client is using SSL/TLS, and bufio.Reader
would read from the original Conn
, thus the handshake in tls.Conn
would fail.
So is there any way to peek into a Conn
in Go (something like MSG_PEEK
in C/C++ sockets)? Or, to create a tls.Conn
after I had read out the first few bytes from the underlying Conn
?