Browse Source

auto update script executed

Toby Chui 1 year ago
parent
commit
0508a7a5a4
1 changed files with 5 additions and 3 deletions
  1. 5 3
      mod/dynamicproxy/dpcore/dpcore.go

+ 5 - 3
mod/dynamicproxy/dpcore/dpcore.go

@@ -309,9 +309,11 @@ func (p *ReverseProxy) ProxyHTTP(rw http.ResponseWriter, req *http.Request, rrr
 			domainWithoutPort = strings.Split(rrr.ProxyDomain, ":")[0]
 		}
 
-		//Trim away the source headers if exists
-		locationRewrite = strings.TrimPrefix(locationRewrite, "http://"+rrr.ProxyDomain)
-		locationRewrite = strings.TrimPrefix(locationRewrite, "http://"+domainWithoutPort)
+		hostname := req.Header.Get("Host")
+
+		//Replace the forwarded target with expected Host
+		locationRewrite = strings.ReplaceAll(locationRewrite, rrr.ProxyDomain, hostname)
+		locationRewrite = strings.ReplaceAll(locationRewrite, domainWithoutPort, hostname)
 
 		//Custom redirection to this rproxy relative path
 		res.Header.Set("Location", locationRewrite)