mirror of
https://github.com/TeaOSLab/EdgeAPI.git
synced 2025-11-08 19:31:54 +08:00
反向代理设置中增加移除回源主机名端口功能
This commit is contained in:
@@ -99,17 +99,18 @@ func (this *ReverseProxyDAO) ComposeReverseProxyConfig(tx *dbs.Tx, reverseProxyI
|
|||||||
return nil, nil
|
return nil, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
config := &serverconfigs.ReverseProxyConfig{}
|
var config = &serverconfigs.ReverseProxyConfig{}
|
||||||
config.Id = int64(reverseProxy.Id)
|
config.Id = int64(reverseProxy.Id)
|
||||||
config.IsOn = reverseProxy.IsOn
|
config.IsOn = reverseProxy.IsOn
|
||||||
config.RequestHostType = types.Int8(reverseProxy.RequestHostType)
|
config.RequestHostType = types.Int8(reverseProxy.RequestHostType)
|
||||||
config.RequestHost = reverseProxy.RequestHost
|
config.RequestHost = reverseProxy.RequestHost
|
||||||
|
config.RequestHostExcludingPort = reverseProxy.RequestHostExcludingPort
|
||||||
config.RequestURI = reverseProxy.RequestURI
|
config.RequestURI = reverseProxy.RequestURI
|
||||||
config.StripPrefix = reverseProxy.StripPrefix
|
config.StripPrefix = reverseProxy.StripPrefix
|
||||||
config.AutoFlush = reverseProxy.AutoFlush == 1
|
config.AutoFlush = reverseProxy.AutoFlush == 1
|
||||||
config.FollowRedirects = reverseProxy.FollowRedirects == 1
|
config.FollowRedirects = reverseProxy.FollowRedirects == 1
|
||||||
|
|
||||||
schedulingConfig := &serverconfigs.SchedulingConfig{}
|
var schedulingConfig = &serverconfigs.SchedulingConfig{}
|
||||||
if IsNotNull(reverseProxy.Scheduling) {
|
if IsNotNull(reverseProxy.Scheduling) {
|
||||||
err = json.Unmarshal(reverseProxy.Scheduling, schedulingConfig)
|
err = json.Unmarshal(reverseProxy.Scheduling, schedulingConfig)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -118,7 +119,7 @@ func (this *ReverseProxyDAO) ComposeReverseProxyConfig(tx *dbs.Tx, reverseProxyI
|
|||||||
config.Scheduling = schedulingConfig
|
config.Scheduling = schedulingConfig
|
||||||
}
|
}
|
||||||
if IsNotNull(reverseProxy.PrimaryOrigins) {
|
if IsNotNull(reverseProxy.PrimaryOrigins) {
|
||||||
originRefs := []*serverconfigs.OriginRef{}
|
var originRefs = []*serverconfigs.OriginRef{}
|
||||||
err = json.Unmarshal(reverseProxy.PrimaryOrigins, &originRefs)
|
err = json.Unmarshal(reverseProxy.PrimaryOrigins, &originRefs)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
@@ -135,13 +136,13 @@ func (this *ReverseProxyDAO) ComposeReverseProxyConfig(tx *dbs.Tx, reverseProxyI
|
|||||||
}
|
}
|
||||||
|
|
||||||
if IsNotNull(reverseProxy.BackupOrigins) {
|
if IsNotNull(reverseProxy.BackupOrigins) {
|
||||||
originRefs := []*serverconfigs.OriginRef{}
|
var originRefs = []*serverconfigs.OriginRef{}
|
||||||
err = json.Unmarshal(reverseProxy.BackupOrigins, &originRefs)
|
err = json.Unmarshal(reverseProxy.BackupOrigins, &originRefs)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
for _, originConfig := range originRefs {
|
for _, ref := range originRefs {
|
||||||
originConfig, err := SharedOriginDAO.ComposeOriginConfig(tx, originConfig.OriginId, cacheMap)
|
originConfig, err := SharedOriginDAO.ComposeOriginConfig(tx, ref.OriginId, cacheMap)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
@@ -153,7 +154,7 @@ func (this *ReverseProxyDAO) ComposeReverseProxyConfig(tx *dbs.Tx, reverseProxyI
|
|||||||
|
|
||||||
// add headers
|
// add headers
|
||||||
if IsNotNull(reverseProxy.AddHeaders) {
|
if IsNotNull(reverseProxy.AddHeaders) {
|
||||||
addHeaders := []string{}
|
var addHeaders = []string{}
|
||||||
err = json.Unmarshal(reverseProxy.AddHeaders, &addHeaders)
|
err = json.Unmarshal(reverseProxy.AddHeaders, &addHeaders)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
@@ -166,7 +167,7 @@ func (this *ReverseProxyDAO) ComposeReverseProxyConfig(tx *dbs.Tx, reverseProxyI
|
|||||||
config.MaxIdleConns = int(reverseProxy.MaxIdleConns)
|
config.MaxIdleConns = int(reverseProxy.MaxIdleConns)
|
||||||
|
|
||||||
if IsNotNull(reverseProxy.ConnTimeout) {
|
if IsNotNull(reverseProxy.ConnTimeout) {
|
||||||
connTimeout := &shared.TimeDuration{}
|
var connTimeout = &shared.TimeDuration{}
|
||||||
err = json.Unmarshal(reverseProxy.ConnTimeout, &connTimeout)
|
err = json.Unmarshal(reverseProxy.ConnTimeout, &connTimeout)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
@@ -175,7 +176,7 @@ func (this *ReverseProxyDAO) ComposeReverseProxyConfig(tx *dbs.Tx, reverseProxyI
|
|||||||
}
|
}
|
||||||
|
|
||||||
if IsNotNull(reverseProxy.ReadTimeout) {
|
if IsNotNull(reverseProxy.ReadTimeout) {
|
||||||
readTimeout := &shared.TimeDuration{}
|
var readTimeout = &shared.TimeDuration{}
|
||||||
err = json.Unmarshal(reverseProxy.ReadTimeout, &readTimeout)
|
err = json.Unmarshal(reverseProxy.ReadTimeout, &readTimeout)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
@@ -184,7 +185,7 @@ func (this *ReverseProxyDAO) ComposeReverseProxyConfig(tx *dbs.Tx, reverseProxyI
|
|||||||
}
|
}
|
||||||
|
|
||||||
if IsNotNull(reverseProxy.IdleTimeout) {
|
if IsNotNull(reverseProxy.IdleTimeout) {
|
||||||
idleTimeout := &shared.TimeDuration{}
|
var idleTimeout = &shared.TimeDuration{}
|
||||||
err = json.Unmarshal(reverseProxy.IdleTimeout, &idleTimeout)
|
err = json.Unmarshal(reverseProxy.IdleTimeout, &idleTimeout)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
@@ -304,6 +305,7 @@ func (this *ReverseProxyDAO) UpdateReverseProxy(tx *dbs.Tx,
|
|||||||
reverseProxyId int64,
|
reverseProxyId int64,
|
||||||
requestHostType int8,
|
requestHostType int8,
|
||||||
requestHost string,
|
requestHost string,
|
||||||
|
requestHostExcludingPort bool,
|
||||||
requestURI string,
|
requestURI string,
|
||||||
stripPrefix string,
|
stripPrefix string,
|
||||||
autoFlush bool,
|
autoFlush bool,
|
||||||
@@ -328,6 +330,7 @@ func (this *ReverseProxyDAO) UpdateReverseProxy(tx *dbs.Tx,
|
|||||||
op.RequestHostType = requestHostType
|
op.RequestHostType = requestHostType
|
||||||
|
|
||||||
op.RequestHost = requestHost
|
op.RequestHost = requestHost
|
||||||
|
op.RequestHostExcludingPort = requestHostExcludingPort
|
||||||
op.RequestURI = requestURI
|
op.RequestURI = requestURI
|
||||||
op.StripPrefix = stripPrefix
|
op.StripPrefix = stripPrefix
|
||||||
op.AutoFlush = autoFlush
|
op.AutoFlush = autoFlush
|
||||||
|
|||||||
@@ -15,6 +15,7 @@ type ReverseProxy struct {
|
|||||||
StripPrefix string `field:"stripPrefix"` // 去除URL前缀
|
StripPrefix string `field:"stripPrefix"` // 去除URL前缀
|
||||||
RequestHostType uint8 `field:"requestHostType"` // 请求Host类型
|
RequestHostType uint8 `field:"requestHostType"` // 请求Host类型
|
||||||
RequestHost string `field:"requestHost"` // 请求Host
|
RequestHost string `field:"requestHost"` // 请求Host
|
||||||
|
RequestHostExcludingPort bool `field:"requestHostExcludingPort"` // 移除请求Host中的域名
|
||||||
RequestURI string `field:"requestURI"` // 请求URI
|
RequestURI string `field:"requestURI"` // 请求URI
|
||||||
AutoFlush uint8 `field:"autoFlush"` // 是否自动刷新缓冲区
|
AutoFlush uint8 `field:"autoFlush"` // 是否自动刷新缓冲区
|
||||||
AddHeaders dbs.JSON `field:"addHeaders"` // 自动添加的Header列表
|
AddHeaders dbs.JSON `field:"addHeaders"` // 自动添加的Header列表
|
||||||
@@ -41,6 +42,7 @@ type ReverseProxyOperator struct {
|
|||||||
StripPrefix interface{} // 去除URL前缀
|
StripPrefix interface{} // 去除URL前缀
|
||||||
RequestHostType interface{} // 请求Host类型
|
RequestHostType interface{} // 请求Host类型
|
||||||
RequestHost interface{} // 请求Host
|
RequestHost interface{} // 请求Host
|
||||||
|
RequestHostExcludingPort interface{} // 移除请求Host中的域名
|
||||||
RequestURI interface{} // 请求URI
|
RequestURI interface{} // 请求URI
|
||||||
AutoFlush interface{} // 是否自动刷新缓冲区
|
AutoFlush interface{} // 是否自动刷新缓冲区
|
||||||
AddHeaders interface{} // 自动添加的Header列表
|
AddHeaders interface{} // 自动添加的Header列表
|
||||||
|
|||||||
@@ -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)
|
config, err := models.SharedReverseProxyDAO.ComposeReverseProxyConfig(tx, req.ReverseProxyId, nil)
|
||||||
if err != 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{}
|
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 {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|||||||
File diff suppressed because one or more lines are too long
Reference in New Issue
Block a user