Jelajahi Sumber

auto update script executed

Toby Chui 1 tahun lalu
induk
melakukan
5045d397d5
1 mengubah file dengan 8 tambahan dan 5 penghapusan
  1. 8 5
      mod/dynamicproxy/redirection/handler.go

+ 8 - 5
mod/dynamicproxy/redirection/handler.go

@@ -13,16 +13,16 @@ import (
 	redirection request
 */
 
-//Check if a request URL is a redirectable URI
+// Check if a request URL is a redirectable URI
 func (t *RuleTable) IsRedirectable(r *http.Request) bool {
 	requestPath := r.Host + r.URL.Path
 	rr := t.MatchRedirectRule(requestPath)
 	return rr != nil
 }
 
-//Handle the redirect request, return after calling this function to prevent
-//multiple write to the response writer
-//Return the status code of the redirection handling
+// Handle the redirect request, return after calling this function to prevent
+// multiple write to the response writer
+// Return the status code of the redirection handling
 func (t *RuleTable) HandleRedirect(w http.ResponseWriter, r *http.Request) int {
 	requestPath := r.Host + r.URL.Path
 	rr := t.MatchRedirectRule(requestPath)
@@ -34,7 +34,10 @@ func (t *RuleTable) HandleRedirect(w http.ResponseWriter, r *http.Request) int {
 		}
 		if rr.ForwardChildpath {
 			//Remove the first / in the path
-			redirectTarget += r.URL.Path[1:] + "?" + r.URL.RawQuery
+			redirectTarget += strings.TrimPrefix(r.URL.Path, "/")
+			if r.URL.RawQuery != "" {
+				redirectTarget += "?" + r.URL.RawQuery
+			}
 		}
 
 		if !strings.HasPrefix(redirectTarget, "http://") && !strings.HasPrefix(redirectTarget, "https://") {