Browse Source

auto update script executed

Toby Chui 1 year ago
parent
commit
13a8b12879
2 changed files with 8 additions and 3 deletions
  1. 7 3
      mod/dynamicproxy/dpcore/dpcore.go
  2. 1 0
      mod/dynamicproxy/proxyRequestHandler.go

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

@@ -2,7 +2,6 @@ package dpcore
 
 import (
 	"errors"
-	"fmt"
 	"io"
 	"log"
 	"net"
@@ -65,6 +64,7 @@ type ResponseRewriteRuleSet struct {
 	ProxyDomain  string
 	OriginalHost string
 	UseTLS       bool
+	PathPrefix   string //Vdir prefix for root, / will be rewrite to this
 }
 
 type requestCanceler interface {
@@ -353,15 +353,19 @@ func (p *ReverseProxy) ProxyHTTP(rw http.ResponseWriter, req *http.Request, rrr
 		if strings.HasPrefix(originLocation, "http://") || strings.HasPrefix(originLocation, "https://") {
 			//Full path
 			//Replace the forwarded target with expected Host
-			fmt.Println(rrr.ProxyDomain, domainWithoutPort, rrr.OriginalHost)
-			lr, err := replaceLocationHost(locationRewrite, rrr.OriginalHost, req.TLS == nil)
+			lr, err := replaceLocationHost(locationRewrite, rrr.OriginalHost, req.TLS != nil)
 			if err == nil {
 				locationRewrite = lr
 			}
 			//locationRewrite = strings.ReplaceAll(locationRewrite, rrr.ProxyDomain, rrr.OriginalHost)
 			//locationRewrite = strings.ReplaceAll(locationRewrite, domainWithoutPort, rrr.OriginalHost)
+		} else if strings.HasPrefix(originLocation, "/") && rrr.PathPrefix != "" {
+			//Back to the root of this proxy object
+			//fmt.Println(rrr.ProxyDomain, domainWithoutPort, rrr.OriginalHost)
+			locationRewrite = strings.TrimSuffix(rrr.PathPrefix, "/") + originLocation
 		} else {
 			//Relative path. Do not modifiy location header
+
 		}
 
 		//Custom redirection to this rproxy relative path

+ 1 - 0
mod/dynamicproxy/proxyRequestHandler.go

@@ -121,6 +121,7 @@ func (h *ProxyHandler) proxyRequest(w http.ResponseWriter, r *http.Request, targ
 		ProxyDomain:  target.Domain,
 		OriginalHost: originalHostHeader,
 		UseTLS:       target.RequireTLS,
+		PathPrefix:   target.Root,
 	})
 
 	var dnsError *net.DNSError