Răsfoiți Sursa

auto update script executed

Toby Chui 1 an în urmă
părinte
comite
2ab49238d8

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

@@ -62,7 +62,8 @@ type ReverseProxy struct {
 }
 
 type ResponseRewriteRuleSet struct {
-	ProxyDomain string
+	ProxyDomain  string
+	OriginalHost string
 }
 
 type requestCanceler interface {
@@ -239,8 +240,6 @@ func (p *ReverseProxy) ProxyHTTP(rw http.ResponseWriter, req *http.Request, rrr
 		transport = http.DefaultTransport
 	}
 
-	hostname := req.Header.Get("Host")
-
 	outreq := new(http.Request)
 	// Shallow copies of maps, like header
 	*outreq = *req
@@ -312,11 +311,11 @@ func (p *ReverseProxy) ProxyHTTP(rw http.ResponseWriter, req *http.Request, rrr
 			domainWithoutPort = strings.Split(rrr.ProxyDomain, ":")[0]
 		}
 
-		fmt.Println(hostname)
+		fmt.Println(rrr.OriginalHost)
 
 		//Replace the forwarded target with expected Host
-		locationRewrite = strings.ReplaceAll(locationRewrite, rrr.ProxyDomain, hostname)
-		locationRewrite = strings.ReplaceAll(locationRewrite, domainWithoutPort, hostname)
+		locationRewrite = strings.ReplaceAll(locationRewrite, rrr.ProxyDomain, rrr.OriginalHost)
+		locationRewrite = strings.ReplaceAll(locationRewrite, domainWithoutPort, rrr.OriginalHost)
 
 		//Custom redirection to this rproxy relative path
 		res.Header.Set("Location", locationRewrite)

+ 3 - 1
mod/dynamicproxy/proxyRequestHandler.go

@@ -117,9 +117,11 @@ func (h *ProxyHandler) proxyRequest(w http.ResponseWriter, r *http.Request, targ
 		return
 	}
 
+	originalHostHeader := r.Host
 	r.Host = r.URL.Host
 	err := target.Proxy.ServeHTTP(w, r, &dpcore.ResponseRewriteRuleSet{
-		ProxyDomain: target.Domain,
+		ProxyDomain:  target.Domain,
+		OriginalHost: originalHostHeader,
 	})
 
 	var dnsError *net.DNSError