Skip to content

Commit 762774c

Browse files
committed
Improve handle connection logging.
1 parent 396afbd commit 762774c

File tree

1 file changed

+9
-4
lines changed

1 file changed

+9
-4
lines changed

domain-proxy/domain_proxy_server.go

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -111,9 +111,12 @@ func (dps *DomainProxyServer) handleConnectionRequest(domainConnection net.Conn)
111111

112112
func (dps *DomainProxyServer) handleHttpConnection(sourceConnection net.Conn, writer http.ResponseWriter, request *http.Request) {
113113
connectionNo := dps.httpConnectionCounter.Add(1)
114-
Logger.Printf("Handling %s Connection %d", DomainSocketToHttp, connectionNo)
115114
targetHost, targetPort := getTargetHostAndPort(request.Host, HttpPort)
115+
Logger.Printf("Handling %s Connection %d with target host %s and port %d", DomainSocketToHttp, connectionNo, targetHost, targetPort)
116116
if !dps.isTargetWhitelisted(targetHost, writer) {
117+
if err := sourceConnection.Close(); err != nil {
118+
HandleConnectionCloseError(err)
119+
}
117120
return
118121
}
119122
startTime := time.Now()
@@ -142,9 +145,12 @@ func (dps *DomainProxyServer) handleHttpConnection(sourceConnection net.Conn, wr
142145

143146
func (dps *DomainProxyServer) handleHttpsConnection(sourceConnection net.Conn, writer http.ResponseWriter, request *http.Request) {
144147
connectionNo := dps.httpsConnectionCounter.Add(1)
145-
Logger.Printf("Handling %s Connection %d", DomainSocketToHttps, connectionNo)
146148
targetHost, targetPort := getTargetHostAndPort(request.Host, HttpsPort)
149+
Logger.Printf("Handling %s Connection %d with target host %s and port %d", DomainSocketToHttps, connectionNo, targetHost, targetPort)
147150
if !dps.isTargetWhitelisted(targetHost, writer) {
151+
if err := sourceConnection.Close(); err != nil {
152+
HandleConnectionCloseError(err)
153+
}
148154
return
149155
}
150156
startTime := time.Now()
@@ -184,9 +190,8 @@ func getTargetHostAndPort(host string, defaultPort int) (string, int) {
184190
}
185191

186192
func (dps *DomainProxyServer) isTargetWhitelisted(targetHost string, writer http.ResponseWriter) bool {
187-
Logger.Printf("Target host %s", targetHost)
188193
if !dps.proxyTargetWhitelist[targetHost] && !dps.nonProxyHosts[targetHost] {
189-
message := "Target host is not whitelisted nor a non-proxy host"
194+
message := fmt.Sprintf("Target host %s is not whitelisted nor a non-proxy host", targetHost)
190195
Logger.Println(message)
191196
http.Error(writer, message, http.StatusForbidden)
192197
return false

0 commit comments

Comments
 (0)