diff --git a/internal/nodes/http_request.go b/internal/nodes/http_request.go index acffa0a..29e876b 100644 --- a/internal/nodes/http_request.go +++ b/internal/nodes/http_request.go @@ -86,13 +86,21 @@ type HTTPRequest struct { // 初始化 func (this *HTTPRequest) init() { this.writer = NewHTTPWriter(this, this.RawWriter) - this.web = &serverconfigs.HTTPWebConfig{IsOn: true} + this.web = &serverconfigs.HTTPWebConfig{ + IsOn: true, + } + // this.uri = this.RawReq.URL.RequestURI() // 之所以不使用RequestURI(),是不想让URL中的Path被Encode + var urlPath = this.RawReq.URL.Path + if this.Server.Web != nil && this.Server.Web.MergeSlashes { + urlPath = utils.CleanPath(urlPath) + this.web.MergeSlashes = true + } if len(this.RawReq.URL.RawQuery) > 0 { - this.uri = this.RawReq.URL.Path + "?" + this.RawReq.URL.RawQuery + this.uri = urlPath + "?" + this.RawReq.URL.RawQuery } else { - this.uri = this.RawReq.URL.Path + this.uri = urlPath } this.rawURI = this.uri diff --git a/internal/nodes/http_request_host_redirect.go b/internal/nodes/http_request_host_redirect.go index 99c5fbb..566c1b4 100644 --- a/internal/nodes/http_request_host_redirect.go +++ b/internal/nodes/http_request_host_redirect.go @@ -1,6 +1,7 @@ package nodes import ( + "github.com/TeaOSLab/EdgeNode/internal/utils" "net/http" "strconv" "strings" @@ -8,7 +9,11 @@ import ( // 主机地址快速跳转 func (this *HTTPRequest) doHostRedirect() (blocked bool) { - fullURL := this.requestScheme() + "://" + this.Host + this.RawReq.URL.Path + var urlPath = this.RawReq.URL.Path + if this.web.MergeSlashes { + urlPath = utils.CleanPath(urlPath) + } + fullURL := this.requestScheme() + "://" + this.Host + urlPath for _, u := range this.web.HostRedirects { if !u.IsOn { continue diff --git a/internal/utils/path.go b/internal/utils/path.go index fc77315..c17a7bc 100644 --- a/internal/utils/path.go +++ b/internal/utils/path.go @@ -1,6 +1,6 @@ package utils -// 清理Path中的多余的字符 +// CleanPath 清理Path中的多余的字符 func CleanPath(path string) string { l := len(path) if l == 0 {