mirror of
https://github.com/TeaOSLab/EdgeAPI.git
synced 2025-11-08 03:00:26 +08:00
反向代理设置中增加移除回源主机名端口功能
This commit is contained in:
@@ -99,17 +99,18 @@ func (this *ReverseProxyDAO) ComposeReverseProxyConfig(tx *dbs.Tx, reverseProxyI
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
config := &serverconfigs.ReverseProxyConfig{}
|
||||
var config = &serverconfigs.ReverseProxyConfig{}
|
||||
config.Id = int64(reverseProxy.Id)
|
||||
config.IsOn = reverseProxy.IsOn
|
||||
config.RequestHostType = types.Int8(reverseProxy.RequestHostType)
|
||||
config.RequestHost = reverseProxy.RequestHost
|
||||
config.RequestHostExcludingPort = reverseProxy.RequestHostExcludingPort
|
||||
config.RequestURI = reverseProxy.RequestURI
|
||||
config.StripPrefix = reverseProxy.StripPrefix
|
||||
config.AutoFlush = reverseProxy.AutoFlush == 1
|
||||
config.FollowRedirects = reverseProxy.FollowRedirects == 1
|
||||
|
||||
schedulingConfig := &serverconfigs.SchedulingConfig{}
|
||||
var schedulingConfig = &serverconfigs.SchedulingConfig{}
|
||||
if IsNotNull(reverseProxy.Scheduling) {
|
||||
err = json.Unmarshal(reverseProxy.Scheduling, schedulingConfig)
|
||||
if err != nil {
|
||||
@@ -118,7 +119,7 @@ func (this *ReverseProxyDAO) ComposeReverseProxyConfig(tx *dbs.Tx, reverseProxyI
|
||||
config.Scheduling = schedulingConfig
|
||||
}
|
||||
if IsNotNull(reverseProxy.PrimaryOrigins) {
|
||||
originRefs := []*serverconfigs.OriginRef{}
|
||||
var originRefs = []*serverconfigs.OriginRef{}
|
||||
err = json.Unmarshal(reverseProxy.PrimaryOrigins, &originRefs)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@@ -135,13 +136,13 @@ func (this *ReverseProxyDAO) ComposeReverseProxyConfig(tx *dbs.Tx, reverseProxyI
|
||||
}
|
||||
|
||||
if IsNotNull(reverseProxy.BackupOrigins) {
|
||||
originRefs := []*serverconfigs.OriginRef{}
|
||||
var originRefs = []*serverconfigs.OriginRef{}
|
||||
err = json.Unmarshal(reverseProxy.BackupOrigins, &originRefs)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
for _, originConfig := range originRefs {
|
||||
originConfig, err := SharedOriginDAO.ComposeOriginConfig(tx, originConfig.OriginId, cacheMap)
|
||||
for _, ref := range originRefs {
|
||||
originConfig, err := SharedOriginDAO.ComposeOriginConfig(tx, ref.OriginId, cacheMap)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -153,7 +154,7 @@ func (this *ReverseProxyDAO) ComposeReverseProxyConfig(tx *dbs.Tx, reverseProxyI
|
||||
|
||||
// add headers
|
||||
if IsNotNull(reverseProxy.AddHeaders) {
|
||||
addHeaders := []string{}
|
||||
var addHeaders = []string{}
|
||||
err = json.Unmarshal(reverseProxy.AddHeaders, &addHeaders)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@@ -166,7 +167,7 @@ func (this *ReverseProxyDAO) ComposeReverseProxyConfig(tx *dbs.Tx, reverseProxyI
|
||||
config.MaxIdleConns = int(reverseProxy.MaxIdleConns)
|
||||
|
||||
if IsNotNull(reverseProxy.ConnTimeout) {
|
||||
connTimeout := &shared.TimeDuration{}
|
||||
var connTimeout = &shared.TimeDuration{}
|
||||
err = json.Unmarshal(reverseProxy.ConnTimeout, &connTimeout)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@@ -175,7 +176,7 @@ func (this *ReverseProxyDAO) ComposeReverseProxyConfig(tx *dbs.Tx, reverseProxyI
|
||||
}
|
||||
|
||||
if IsNotNull(reverseProxy.ReadTimeout) {
|
||||
readTimeout := &shared.TimeDuration{}
|
||||
var readTimeout = &shared.TimeDuration{}
|
||||
err = json.Unmarshal(reverseProxy.ReadTimeout, &readTimeout)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@@ -184,7 +185,7 @@ func (this *ReverseProxyDAO) ComposeReverseProxyConfig(tx *dbs.Tx, reverseProxyI
|
||||
}
|
||||
|
||||
if IsNotNull(reverseProxy.IdleTimeout) {
|
||||
idleTimeout := &shared.TimeDuration{}
|
||||
var idleTimeout = &shared.TimeDuration{}
|
||||
err = json.Unmarshal(reverseProxy.IdleTimeout, &idleTimeout)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@@ -304,6 +305,7 @@ func (this *ReverseProxyDAO) UpdateReverseProxy(tx *dbs.Tx,
|
||||
reverseProxyId int64,
|
||||
requestHostType int8,
|
||||
requestHost string,
|
||||
requestHostExcludingPort bool,
|
||||
requestURI string,
|
||||
stripPrefix string,
|
||||
autoFlush bool,
|
||||
@@ -328,6 +330,7 @@ func (this *ReverseProxyDAO) UpdateReverseProxy(tx *dbs.Tx,
|
||||
op.RequestHostType = requestHostType
|
||||
|
||||
op.RequestHost = requestHost
|
||||
op.RequestHostExcludingPort = requestHostExcludingPort
|
||||
op.RequestURI = requestURI
|
||||
op.StripPrefix = stripPrefix
|
||||
op.AutoFlush = autoFlush
|
||||
|
||||
@@ -4,55 +4,57 @@ import "github.com/iwind/TeaGo/dbs"
|
||||
|
||||
// ReverseProxy 反向代理配置
|
||||
type ReverseProxy struct {
|
||||
Id uint32 `field:"id"` // ID
|
||||
AdminId uint32 `field:"adminId"` // 管理员ID
|
||||
UserId uint32 `field:"userId"` // 用户ID
|
||||
TemplateId uint32 `field:"templateId"` // 模版ID
|
||||
IsOn bool `field:"isOn"` // 是否启用
|
||||
Scheduling dbs.JSON `field:"scheduling"` // 调度算法
|
||||
PrimaryOrigins dbs.JSON `field:"primaryOrigins"` // 主要源站
|
||||
BackupOrigins dbs.JSON `field:"backupOrigins"` // 备用源站
|
||||
StripPrefix string `field:"stripPrefix"` // 去除URL前缀
|
||||
RequestHostType uint8 `field:"requestHostType"` // 请求Host类型
|
||||
RequestHost string `field:"requestHost"` // 请求Host
|
||||
RequestURI string `field:"requestURI"` // 请求URI
|
||||
AutoFlush uint8 `field:"autoFlush"` // 是否自动刷新缓冲区
|
||||
AddHeaders dbs.JSON `field:"addHeaders"` // 自动添加的Header列表
|
||||
State uint8 `field:"state"` // 状态
|
||||
CreatedAt uint64 `field:"createdAt"` // 创建时间
|
||||
ConnTimeout dbs.JSON `field:"connTimeout"` // 连接超时时间
|
||||
ReadTimeout dbs.JSON `field:"readTimeout"` // 读取超时时间
|
||||
IdleTimeout dbs.JSON `field:"idleTimeout"` // 空闲超时时间
|
||||
MaxConns uint32 `field:"maxConns"` // 最大并发连接数
|
||||
MaxIdleConns uint32 `field:"maxIdleConns"` // 最大空闲连接数
|
||||
ProxyProtocol dbs.JSON `field:"proxyProtocol"` // Proxy Protocol配置
|
||||
FollowRedirects uint8 `field:"followRedirects"` // 回源跟随
|
||||
Id uint32 `field:"id"` // ID
|
||||
AdminId uint32 `field:"adminId"` // 管理员ID
|
||||
UserId uint32 `field:"userId"` // 用户ID
|
||||
TemplateId uint32 `field:"templateId"` // 模版ID
|
||||
IsOn bool `field:"isOn"` // 是否启用
|
||||
Scheduling dbs.JSON `field:"scheduling"` // 调度算法
|
||||
PrimaryOrigins dbs.JSON `field:"primaryOrigins"` // 主要源站
|
||||
BackupOrigins dbs.JSON `field:"backupOrigins"` // 备用源站
|
||||
StripPrefix string `field:"stripPrefix"` // 去除URL前缀
|
||||
RequestHostType uint8 `field:"requestHostType"` // 请求Host类型
|
||||
RequestHost string `field:"requestHost"` // 请求Host
|
||||
RequestHostExcludingPort bool `field:"requestHostExcludingPort"` // 移除请求Host中的域名
|
||||
RequestURI string `field:"requestURI"` // 请求URI
|
||||
AutoFlush uint8 `field:"autoFlush"` // 是否自动刷新缓冲区
|
||||
AddHeaders dbs.JSON `field:"addHeaders"` // 自动添加的Header列表
|
||||
State uint8 `field:"state"` // 状态
|
||||
CreatedAt uint64 `field:"createdAt"` // 创建时间
|
||||
ConnTimeout dbs.JSON `field:"connTimeout"` // 连接超时时间
|
||||
ReadTimeout dbs.JSON `field:"readTimeout"` // 读取超时时间
|
||||
IdleTimeout dbs.JSON `field:"idleTimeout"` // 空闲超时时间
|
||||
MaxConns uint32 `field:"maxConns"` // 最大并发连接数
|
||||
MaxIdleConns uint32 `field:"maxIdleConns"` // 最大空闲连接数
|
||||
ProxyProtocol dbs.JSON `field:"proxyProtocol"` // Proxy Protocol配置
|
||||
FollowRedirects uint8 `field:"followRedirects"` // 回源跟随
|
||||
}
|
||||
|
||||
type ReverseProxyOperator struct {
|
||||
Id interface{} // ID
|
||||
AdminId interface{} // 管理员ID
|
||||
UserId interface{} // 用户ID
|
||||
TemplateId interface{} // 模版ID
|
||||
IsOn interface{} // 是否启用
|
||||
Scheduling interface{} // 调度算法
|
||||
PrimaryOrigins interface{} // 主要源站
|
||||
BackupOrigins interface{} // 备用源站
|
||||
StripPrefix interface{} // 去除URL前缀
|
||||
RequestHostType interface{} // 请求Host类型
|
||||
RequestHost interface{} // 请求Host
|
||||
RequestURI interface{} // 请求URI
|
||||
AutoFlush interface{} // 是否自动刷新缓冲区
|
||||
AddHeaders interface{} // 自动添加的Header列表
|
||||
State interface{} // 状态
|
||||
CreatedAt interface{} // 创建时间
|
||||
ConnTimeout interface{} // 连接超时时间
|
||||
ReadTimeout interface{} // 读取超时时间
|
||||
IdleTimeout interface{} // 空闲超时时间
|
||||
MaxConns interface{} // 最大并发连接数
|
||||
MaxIdleConns interface{} // 最大空闲连接数
|
||||
ProxyProtocol interface{} // Proxy Protocol配置
|
||||
FollowRedirects interface{} // 回源跟随
|
||||
Id interface{} // ID
|
||||
AdminId interface{} // 管理员ID
|
||||
UserId interface{} // 用户ID
|
||||
TemplateId interface{} // 模版ID
|
||||
IsOn interface{} // 是否启用
|
||||
Scheduling interface{} // 调度算法
|
||||
PrimaryOrigins interface{} // 主要源站
|
||||
BackupOrigins interface{} // 备用源站
|
||||
StripPrefix interface{} // 去除URL前缀
|
||||
RequestHostType interface{} // 请求Host类型
|
||||
RequestHost interface{} // 请求Host
|
||||
RequestHostExcludingPort interface{} // 移除请求Host中的域名
|
||||
RequestURI interface{} // 请求URI
|
||||
AutoFlush interface{} // 是否自动刷新缓冲区
|
||||
AddHeaders interface{} // 自动添加的Header列表
|
||||
State interface{} // 状态
|
||||
CreatedAt interface{} // 创建时间
|
||||
ConnTimeout interface{} // 连接超时时间
|
||||
ReadTimeout interface{} // 读取超时时间
|
||||
IdleTimeout interface{} // 空闲超时时间
|
||||
MaxConns interface{} // 最大并发连接数
|
||||
MaxIdleConns interface{} // 最大空闲连接数
|
||||
ProxyProtocol interface{} // Proxy Protocol配置
|
||||
FollowRedirects interface{} // 回源跟随
|
||||
}
|
||||
|
||||
func NewReverseProxyOperator() *ReverseProxyOperator {
|
||||
|
||||
@@ -84,7 +84,7 @@ func (this *ReverseProxyService) FindEnabledReverseProxyConfig(ctx context.Conte
|
||||
}
|
||||
}
|
||||
|
||||
tx := this.NullTx()
|
||||
var tx = this.NullTx()
|
||||
|
||||
config, err := models.SharedReverseProxyDAO.ComposeReverseProxyConfig(tx, req.ReverseProxyId, nil)
|
||||
if err != nil {
|
||||
@@ -189,7 +189,7 @@ func (this *ReverseProxyService) UpdateReverseProxy(ctx context.Context, req *pb
|
||||
}
|
||||
}
|
||||
|
||||
tx := this.NullTx()
|
||||
var tx = this.NullTx()
|
||||
|
||||
// 校验参数
|
||||
var connTimeout = &shared.TimeDuration{}
|
||||
@@ -216,7 +216,7 @@ func (this *ReverseProxyService) UpdateReverseProxy(ctx context.Context, req *pb
|
||||
}
|
||||
}
|
||||
|
||||
err = models.SharedReverseProxyDAO.UpdateReverseProxy(tx, req.ReverseProxyId, types.Int8(req.RequestHostType), req.RequestHost, req.RequestURI, req.StripPrefix, req.AutoFlush, req.AddHeaders, connTimeout, readTimeout, idleTimeout, req.MaxConns, req.MaxIdleConns, req.ProxyProtocolJSON, req.FollowRedirects)
|
||||
err = models.SharedReverseProxyDAO.UpdateReverseProxy(tx, req.ReverseProxyId, types.Int8(req.RequestHostType), req.RequestHost, req.RequestHostExcludingPort, req.RequestURI, req.StripPrefix, req.AutoFlush, req.AddHeaders, connTimeout, readTimeout, idleTimeout, req.MaxConns, req.MaxIdleConns, req.ProxyProtocolJSON, req.FollowRedirects)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
File diff suppressed because one or more lines are too long
Reference in New Issue
Block a user