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.