在net.Conn上创建一个http响应编写器

In the following code:

l, err := net.Listen("tcp", ":"+port)
assert(err)
c, err := l.Accept()
assert(err)
cert, err := tls.LoadX509KeyPair(TLS_CERT, TLS_PKEY)
assert(err)
TLSconfig := &tls.Config{
    Certificates: []tls.Certificate{cert},
    ClientAuth:   tls.VerifyClientCertIfGiven,
    ServerName:   DOMAIN_NAME,
}
tlsConn := tls.Server(c, TLSconfig)
tlsConn.Handshake()
c = net.Conn(tlsConn)

I would like to create an http response writer, e.g.:

w := CreateResponseWriter(c)  //<-- how to do this?
w.Header().Set(...)
if !Authorized(c.RemoteAddr()) {
    http.Error(w, "Unauthorized", http.StatusUnauthorized)
    return
}
data, _ := os.Open("/path/to/content")
defer data.Close()
io.Copy(w, data)

The purpose is that I am writing an http proxy in Golang, I will need to check if the remote connection is authorized or not, if not, I will show the login page. Thanks.

http.ResponseWriter is an interface. So to create your own, just make any data type that satisfies the interface.

But it looks like what you're really trying to do is just bind your HTTP server to an existing connection. For that you can use the Serve or ServeTLS methods.