Browse Source

auto update script executed

Toby Chui 2 years ago
parent
commit
43b7bd69b2
3 changed files with 19 additions and 2 deletions
  1. 14 2
      mod/dynamicproxy/dynamicproxy.go
  2. 5 0
      reverseproxy.go
  3. BIN
      sys.db

+ 14 - 2
mod/dynamicproxy/dynamicproxy.go

@@ -209,9 +209,21 @@ func (h *ProxyHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
 		}
 	}
 
-	fmt.Println(r.RequestURI)
+	//Clean up the request URI
+	proxyingPath := strings.TrimSpace(r.RequestURI)
+	/*
+		requestingRsc := filepath.Base(r.RequestURI)
+		if !strings.Contains(requestingRsc, ".") {
+			//Not a file. Add the tail slash if not exists
+			if proxyingPath[len(proxyingPath)-1:] != "/" {
+				proxyingPath = proxyingPath + "/"
+				http.Redirect(w, r, proxyingPath, http.StatusTemporaryRedirect)
+				return
+			}
+		}
+	*/
 
-	targetProxyEndpoint := h.Parent.getTargetProxyEndpointFromRequestURI(r.RequestURI)
+	targetProxyEndpoint := h.Parent.getTargetProxyEndpointFromRequestURI(proxyingPath)
 	if targetProxyEndpoint != nil {
 		h.proxyRequest(w, r, targetProxyEndpoint)
 	} else {

+ 5 - 0
reverseproxy.go

@@ -6,6 +6,7 @@ import (
 	"net/http"
 	"path/filepath"
 	"strconv"
+	"strings"
 
 	"imuslab.com/arozos/ReverseProxy/mod/dynamicproxy"
 )
@@ -118,6 +119,10 @@ func ReverseProxyHandleAddEndpoint(w http.ResponseWriter, r *http.Request) {
 			sendErrorResponse(w, "vdir not defined")
 			return
 		}
+
+		if !strings.HasPrefix(vdir, "/") {
+			vdir = "/" + vdir
+		}
 		rootname = vdir
 		dynamicProxyRouter.AddVirtualDirectoryProxyService(vdir, endpoint, useTLS)
 

BIN
sys.db