服务增加是否合并URL中的多余分隔符选项

This commit is contained in:
GoEdgeLab
2021-11-24 14:50:07 +08:00
parent b3c8f94d11
commit aa9ce4e260
3 changed files with 18 additions and 5 deletions

View File

@@ -86,13 +86,21 @@ type HTTPRequest struct {
// 初始化 // 初始化
func (this *HTTPRequest) init() { func (this *HTTPRequest) init() {
this.writer = NewHTTPWriter(this, this.RawWriter) this.writer = NewHTTPWriter(this, this.RawWriter)
this.web = &serverconfigs.HTTPWebConfig{IsOn: true} this.web = &serverconfigs.HTTPWebConfig{
IsOn: true,
}
// this.uri = this.RawReq.URL.RequestURI() // this.uri = this.RawReq.URL.RequestURI()
// 之所以不使用RequestURI()是不想让URL中的Path被Encode // 之所以不使用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 { 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 { } else {
this.uri = this.RawReq.URL.Path this.uri = urlPath
} }
this.rawURI = this.uri this.rawURI = this.uri

View File

@@ -1,6 +1,7 @@
package nodes package nodes
import ( import (
"github.com/TeaOSLab/EdgeNode/internal/utils"
"net/http" "net/http"
"strconv" "strconv"
"strings" "strings"
@@ -8,7 +9,11 @@ import (
// 主机地址快速跳转 // 主机地址快速跳转
func (this *HTTPRequest) doHostRedirect() (blocked bool) { 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 { for _, u := range this.web.HostRedirects {
if !u.IsOn { if !u.IsOn {
continue continue

View File

@@ -1,6 +1,6 @@
package utils package utils
// 清理Path中的多余的字符 // CleanPath 清理Path中的多余的字符
func CleanPath(path string) string { func CleanPath(path string) string {
l := len(path) l := len(path)
if l == 0 { if l == 0 {