URL跳转增加匹配前缀和是否保留RequestURI选项

This commit is contained in:
GoEdgeLab
2021-04-07 11:20:44 +08:00
parent 1b00199f37
commit fabef83a4c

View File

@@ -1,6 +1,9 @@
package nodes
import "net/http"
import (
"net/http"
"strings"
)
// 主机地址快速跳转
func (this *HTTPRequest) doHostRedirect() (blocked bool) {
@@ -9,13 +12,28 @@ func (this *HTTPRequest) doHostRedirect() (blocked bool) {
if !u.IsOn {
continue
}
if fullURL == u.RealBeforeURL() {
if u.Status <= 0 {
http.Redirect(this.RawWriter, this.RawReq, u.AfterURL, http.StatusTemporaryRedirect)
} else {
http.Redirect(this.RawWriter, this.RawReq, u.AfterURL, u.Status)
if u.MatchPrefix {
if strings.HasPrefix(fullURL, u.BeforeURL) {
afterURL := u.AfterURL
if u.KeepRequestURI {
afterURL += this.RawReq.URL.RequestURI()
}
if u.Status <= 0 {
http.Redirect(this.RawWriter, this.RawReq, afterURL, http.StatusTemporaryRedirect)
} else {
http.Redirect(this.RawWriter, this.RawReq, afterURL, u.Status)
}
return true
}
} else {
if fullURL == u.RealBeforeURL() {
if u.Status <= 0 {
http.Redirect(this.RawWriter, this.RawReq, u.AfterURL, http.StatusTemporaryRedirect)
} else {
http.Redirect(this.RawWriter, this.RawReq, u.AfterURL, u.Status)
}
return true
}
return true
}
}
return