Browse Source

auto update script executed

Toby Chui 1 year ago
parent
commit
a4bca6a9cc

+ 2 - 1
mod/dynamicproxy/dpcore/dpcore.go

@@ -64,6 +64,7 @@ type ReverseProxy struct {
 type ResponseRewriteRuleSet struct {
 	ProxyDomain  string
 	OriginalHost string
+	UseTLS       bool
 }
 
 type requestCanceler interface {
@@ -353,7 +354,7 @@ func (p *ReverseProxy) ProxyHTTP(rw http.ResponseWriter, req *http.Request, rrr
 			//Full path
 			//Replace the forwarded target with expected Host
 			fmt.Println(rrr.ProxyDomain, domainWithoutPort, rrr.OriginalHost)
-			lr, err := replaceLocationHost(locationRewrite, rrr.OriginalHost)
+			lr, err := replaceLocationHost(locationRewrite, rrr.OriginalHost, rrr.UseTLS)
 			if err == nil {
 				locationRewrite = lr
 			}

+ 7 - 13
mod/dynamicproxy/dpcore/utils.go

@@ -2,26 +2,20 @@ package dpcore
 
 import (
 	"net/url"
-	"strings"
 )
 
-func replaceLocationHost(urlString, newHost string) (string, error) {
-	parsedURL, err := url.Parse(urlString)
+func replaceLocationHost(urlString string, newHost string, useTLS bool) (string, error) {
+	u, err := url.Parse(urlString)
 	if err != nil {
 		return "", err
 	}
 
-	// Extract the port number from the host string (if it exists)
-	hostParts := strings.Split(parsedURL.Host, ":")
-	var newHostString string
-	if len(hostParts) > 1 {
-		newHostString = newHost + ":" + hostParts[1]
+	if useTLS {
+		u.Scheme = "https"
 	} else {
-		newHostString = newHost
+		u.Scheme = "http"
 	}
 
-	// Set the new host string
-	parsedURL.Host = newHostString
-
-	return parsedURL.String(), nil
+	u.Host = newHost
+	return u.String(), nil
 }

+ 1 - 0
mod/dynamicproxy/proxyRequestHandler.go

@@ -120,6 +120,7 @@ func (h *ProxyHandler) proxyRequest(w http.ResponseWriter, r *http.Request, targ
 	err := target.Proxy.ServeHTTP(w, r, &dpcore.ResponseRewriteRuleSet{
 		ProxyDomain:  target.Domain,
 		OriginalHost: originalHostHeader,
+		UseTLS:       target.RequireTLS,
 	})
 
 	var dnsError *net.DNSError