|
@@ -13,16 +13,16 @@ import (
|
|
redirection request
|
|
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 {
|
|
func (t *RuleTable) IsRedirectable(r *http.Request) bool {
|
|
requestPath := r.Host + r.URL.Path
|
|
requestPath := r.Host + r.URL.Path
|
|
rr := t.MatchRedirectRule(requestPath)
|
|
rr := t.MatchRedirectRule(requestPath)
|
|
return rr != nil
|
|
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 {
|
|
func (t *RuleTable) HandleRedirect(w http.ResponseWriter, r *http.Request) int {
|
|
requestPath := r.Host + r.URL.Path
|
|
requestPath := r.Host + r.URL.Path
|
|
rr := t.MatchRedirectRule(requestPath)
|
|
rr := t.MatchRedirectRule(requestPath)
|
|
@@ -34,7 +34,10 @@ func (t *RuleTable) HandleRedirect(w http.ResponseWriter, r *http.Request) int {
|
|
}
|
|
}
|
|
if rr.ForwardChildpath {
|
|
if rr.ForwardChildpath {
|
|
//Remove the first / in the path
|
|
//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://") {
|
|
if !strings.HasPrefix(redirectTarget, "http://") && !strings.HasPrefix(redirectTarget, "https://") {
|