From 41cf0cc2c74e6725e5cc73562a4b21e1b9e7b9e1 Mon Sep 17 00:00:00 2001 From: Toby Chui Date: Sun, 19 Oct 2025 22:11:58 +0800 Subject: [PATCH] Fixed #856 Updated upstreamHostSwap to accept currentTarget and avoid swapping to the same proxy endpoint, preventing unnecessary loopback handling. Also bumped SYSTEM_VERSION to 3.2.9. --- src/def.go | 2 +- src/mod/dynamicproxy/proxyRequestHandler.go | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/def.go b/src/def.go index 01a5909..a8a801e 100644 --- a/src/def.go +++ b/src/def.go @@ -44,7 +44,7 @@ import ( const ( /* Build Constants */ SYSTEM_NAME = "Zoraxy" - SYSTEM_VERSION = "3.2.8" + SYSTEM_VERSION = "3.2.9" DEVELOPMENT_BUILD = false /* System Constants */ diff --git a/src/mod/dynamicproxy/proxyRequestHandler.go b/src/mod/dynamicproxy/proxyRequestHandler.go index 7d3f669..35084e0 100644 --- a/src/mod/dynamicproxy/proxyRequestHandler.go +++ b/src/mod/dynamicproxy/proxyRequestHandler.go @@ -110,13 +110,13 @@ func (router *Router) rewriteURL(rooturl string, requestURL string) string { // upstreamHostSwap check if this loopback to one of the proxy rule in the system. If yes, do a shortcut target swap // this prevents unnecessary external DNS lookup and connection, return true if swapped and request is already handled // by the loopback handler. Only continue if return is false -func (h *ProxyHandler) upstreamHostSwap(w http.ResponseWriter, r *http.Request, selectedUpstream *loadbalance.Upstream) bool { +func (h *ProxyHandler) upstreamHostSwap(w http.ResponseWriter, r *http.Request, selectedUpstream *loadbalance.Upstream, currentTarget *ProxyEndpoint) bool { upstreamHostname := selectedUpstream.OriginIpOrDomain if strings.Contains(upstreamHostname, ":") { upstreamHostname = strings.Split(upstreamHostname, ":")[0] } loopbackProxyEndpoint := h.Parent.GetProxyEndpointFromHostname(upstreamHostname) - if loopbackProxyEndpoint != nil { + if loopbackProxyEndpoint != nil && loopbackProxyEndpoint != currentTarget { //This is a loopback request. Swap the target to the loopback target //h.Parent.Option.Logger.PrintAndLog("proxy", "Detected a loopback request to self. Swap the target to "+loopbackProxyEndpoint.RootOrMatchingDomain, nil) if loopbackProxyEndpoint.IsEnabled() { @@ -147,7 +147,7 @@ func (h *ProxyHandler) hostRequest(w http.ResponseWriter, r *http.Request, targe } /* Upstream Host Swap (use to detect loopback to self) */ - if h.upstreamHostSwap(w, r, selectedUpstream) { + if h.upstreamHostSwap(w, r, selectedUpstream, target) { //Request handled by the loopback handler return }