反向代理支持RequestPath、RequestURI等

This commit is contained in:
刘祥超
2020-09-27 10:03:24 +08:00
parent c272658c73
commit cf609dad3f
4 changed files with 127 additions and 86 deletions

View File

@@ -8,7 +8,7 @@ type HTTPRootConfig struct {
IsOn bool `yaml:"isOn" json:"isOn"` // 是否启用
Dir string `yaml:"dir" json:"dir"` // 目录
Indexes []string `yaml:"indexes" json:"indexes"` // 默认首页文件
StripPrefix string `yaml:"stripPrefix" json:"stripPrefix"` // 去除前缀
StripPrefix string `yaml:"stripPrefix" json:"stripPrefix"` // 去除URL前缀
DecodePath bool `yaml:"decodePath" json:"decodePath"` // 是否对请求路径进行解码
IsBreak bool `yaml:"isBreak" json:"isBreak"` // 找不到文件的情况下是否终止

View File

@@ -1,6 +1,7 @@
package serverconfigs
import (
"github.com/TeaOSLab/EdgeCommon/pkg/configutils"
"github.com/TeaOSLab/EdgeCommon/pkg/serverconfigs/schedulingconfigs"
"github.com/TeaOSLab/EdgeCommon/pkg/serverconfigs/shared"
"sync"
@@ -16,7 +17,12 @@ type ReverseProxyConfig struct {
BackupOriginRefs []*OriginRef `yaml:"backupOriginRefs" json:"backupOriginRefs"` // 备用源站引用
Scheduling *SchedulingConfig `yaml:"scheduling" json:"scheduling"` // 调度算法选项
// TODO 可以设置同后端交互的主机名Host并支持变量
StripPrefix string `yaml:"stripPrefix" json:"stripPrefix"` // 去除URL前缀
RequestHost string `yaml:"requestHost" json:"requestHost"` // 请求Host支持变量
RequestURI string `yaml:"requestURI" json:"requestURI"` // 请求URI支持变量如果同时定义了StripPrefix则先执行StripPrefix
requestHostHasVariables bool
requestURIHasVariables bool
hasPrimaryOrigins bool
hasBackupOrigins bool
@@ -27,6 +33,9 @@ type ReverseProxyConfig struct {
// 初始化
func (this *ReverseProxyConfig) Init() error {
this.requestHostHasVariables = configutils.HasVariables(this.RequestHost)
this.requestURIHasVariables = configutils.HasVariables(this.RequestURI)
this.hasPrimaryOrigins = len(this.PrimaryOrigins) > 0
this.hasBackupOrigins = len(this.BackupOrigins) > 0
@@ -140,3 +149,13 @@ func (this *ReverseProxyConfig) FindSchedulingConfig() *SchedulingConfig {
}
return this.Scheduling
}
// 判断RequestHost是否有变量
func (this *ReverseProxyConfig) RequestHostHasVariables() bool {
return this.requestHostHasVariables
}
// 判断RequestURI是否有变量
func (this *ReverseProxyConfig) RequestURIHasVariables() bool {
return this.requestURIHasVariables
}