Browse Source

auto update script executed

Toby Chui 1 year ago
parent
commit
ef2e014f02
2 changed files with 12 additions and 5 deletions
  1. 3 3
      mod/dynamicproxy/Server.go
  2. 9 2
      mod/dynamicproxy/endpoints.go

+ 3 - 3
mod/dynamicproxy/Server.go

@@ -97,7 +97,7 @@ func (h *ProxyHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
 			//Virtual directory routing rule found. Route via vdir mode
 			h.vdirRequest(w, r, targetProxyEndpoint)
 			return
-		} else if !strings.HasSuffix(proxyingPath, "/") {
+		} else if !strings.HasSuffix(proxyingPath, "/") && sep.ProxyType != ProxyType_Root {
 			potentialProxtEndpoint := sep.GetVirtualDirectoryHandlerFromRequestURI(proxyingPath + "/")
 			if potentialProxtEndpoint != nil {
 				//Missing tailing slash. Redirect to target proxy endpoint
@@ -155,7 +155,7 @@ func (h *ProxyHandler) handleRootRouting(w http.ResponseWriter, r *http.Request)
 		fallthrough
 	case DefaultSite_ReverseProxy:
 		//They both share the same behavior
-		h.vdirRequest(w, r, h.Parent.Root)
+		h.hostRequest(w, r, h.Parent.Root)
 	case DefaultSite_Redirect:
 		redirectTarget := strings.TrimSpace(proot.DefaultSiteValue)
 		if redirectTarget == "" {
@@ -166,7 +166,7 @@ func (h *ProxyHandler) handleRootRouting(w http.ResponseWriter, r *http.Request)
 		parsedURL, err := url.Parse(proot.DefaultSiteValue)
 		if err != nil {
 			//Error when parsing target. Send to root
-			h.vdirRequest(w, r, h.Parent.Root)
+			h.hostRequest(w, r, h.Parent.Root)
 			return
 		}
 		hostname := parsedURL.Hostname()

+ 9 - 2
mod/dynamicproxy/endpoints.go

@@ -1,12 +1,19 @@
 package dynamicproxy
 
-import "fmt"
+import (
+	"strings"
+)
 
 /*
 	Endpoint Functions
 */
 
+// Get virtual directory handler from given URI
 func (ep *ProxyEndpoint) GetVirtualDirectoryHandlerFromRequestURI(requestURI string) *VirtualDirectoryEndpoint {
-	fmt.Println(requestURI)
+	for _, vdir := range ep.VirtualDirectories {
+		if strings.HasPrefix(requestURI, vdir.MatchingPath) {
+			return vdir
+		}
+	}
 	return nil
 }