mirror of
https://github.com/TeaOSLab/EdgeCommon.git
synced 2026-04-03 21:05:47 +08:00
反向代理支持RequestPath、RequestURI等
This commit is contained in:
@@ -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"` // 找不到文件的情况下是否终止
|
||||
|
||||
|
||||
@@ -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
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user