When I typically create a http server in Go, I do:
http.ListenAndServeTLS("https://localhost:8999", "key.pem", "pub.pem", nil)
But under the hood that method does:
ln, err := net.Listen("tcp", addr)......for { rw, err := ln.Accept()......}
That is not what I want, but instead I wish to:
...listen, err := net.Listen("tcp", "localhost:8999") if err != nil { return } pair, err := tls.LoadX509KeyPair("pub.pem", "key.pem") if err != nil { return }go func(){for { // Read tcp conn l, err := listen.Accept() if err != nil { return } // Do something, filter etcgo func() { tlsC := tls.Server(l, &tls.Config{ ClientAuth: tls.RequestClientCert, Certificates: []tls.Certificate{pair}, InsecureSkipVerify: true, }) err := tlsC.Handshake() if err != nil { return } // Do something, filter etc // I wish to read HTTP request from tlsC here, but without creating yet another goroutine (as http.Serve does)}()}}()...
So I only want http package to read existing connection and parse it, NOT start listening again on net.Listener.
The whole idea of the code is to being able to filter client connection on each stage (tcp, tls, http) and filter itself being some kind of map[]
, which elements can be called at any time during connection establishing