diff --git a/mirror/header.go b/mirror/header.go index 34f4d36..231537b 100644 --- a/mirror/header.go +++ b/mirror/header.go @@ -2,6 +2,7 @@ package mirror import ( "bufio" + "crypto/tls" "log" "net" "net/http" @@ -43,14 +44,27 @@ func (ml *Mirror) Accept() (net.Conn, error) { // Accept a connection from the listener conn, err := ml.MetaListener.Accept() if err != nil { + log.Println("Error accepting connection:", err) return nil, err } + // Check if the connection is a TLS connection + if tlsConn, ok := conn.(*tls.Conn); ok { + // If it is a TLS connection, perform the handshake + if err := tlsConn.Handshake(); err != nil { + log.Println("Error performing TLS handshake:", err) + return nil, err + } + // If the handshake is successful, get the underlying connection + conn = tlsConn.NetConn() + } + host := map[string]string{ "Host": ml.MetaListener.Addr().String(), "X-Forwarded-For": conn.RemoteAddr().String(), "X-Forwarded-Proto": "http", } + // Add headers to the connection conn = AddHeaders(conn, host)