From aa9ce4e260af868c8f9a8acc4d4390c1b1762c28 Mon Sep 17 00:00:00 2001 From: GoEdgeLab Date: Wed, 24 Nov 2021 14:50:07 +0800 Subject: [PATCH] =?UTF-8?q?=E6=9C=8D=E5=8A=A1=E5=A2=9E=E5=8A=A0=E6=98=AF?= =?UTF-8?q?=E5=90=A6=E5=90=88=E5=B9=B6URL=E4=B8=AD=E7=9A=84=E5=A4=9A?= =?UTF-8?q?=E4=BD=99=E5=88=86=E9=9A=94=E7=AC=A6=E9=80=89=E9=A1=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- internal/nodes/http_request.go | 14 +++++++++++--- internal/nodes/http_request_host_redirect.go | 7 ++++++- internal/utils/path.go | 2 +- 3 files changed, 18 insertions(+), 5 deletions(-) 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 {