支持PROXY Protocol

This commit is contained in:
刘祥超
2021-10-12 20:18:35 +08:00
parent b190479d44
commit 82ed22a464
3 changed files with 32 additions and 3 deletions

View File

@@ -190,6 +190,16 @@ func (this *ReverseProxyDAO) ComposeReverseProxyConfig(tx *dbs.Tx, reverseProxyI
config.IdleTimeout = idleTimeout config.IdleTimeout = idleTimeout
} }
// PROXY Protocol
if IsNotNull(reverseProxy.ProxyProtocol) {
var proxyProtocolConfig = &serverconfigs.ProxyProtocolConfig{}
err = json.Unmarshal([]byte(reverseProxy.ProxyProtocol), proxyProtocolConfig)
if err != nil {
return nil, err
}
config.ProxyProtocol = proxyProtocolConfig
}
cacheMap[cacheKey] = config cacheMap[cacheKey] = config
return config, nil return config, nil
@@ -286,7 +296,20 @@ func (this *ReverseProxyDAO) UpdateReverseProxyBackupOrigins(tx *dbs.Tx, reverse
} }
// UpdateReverseProxy 修改是否启用 // UpdateReverseProxy 修改是否启用
func (this *ReverseProxyDAO) UpdateReverseProxy(tx *dbs.Tx, reverseProxyId int64, requestHostType int8, requestHost string, requestURI string, stripPrefix string, autoFlush bool, addHeaders []string, connTimeout *shared.TimeDuration, readTimeout *shared.TimeDuration, idleTimeout *shared.TimeDuration, maxConns int32, maxIdleConns int32) error { func (this *ReverseProxyDAO) UpdateReverseProxy(tx *dbs.Tx,
reverseProxyId int64,
requestHostType int8,
requestHost string,
requestURI string,
stripPrefix string,
autoFlush bool,
addHeaders []string,
connTimeout *shared.TimeDuration,
readTimeout *shared.TimeDuration,
idleTimeout *shared.TimeDuration,
maxConns int32,
maxIdleConns int32,
proxyProtocolJSON []byte) error {
if reverseProxyId <= 0 { if reverseProxyId <= 0 {
return errors.New("invalid reverseProxyId") return errors.New("invalid reverseProxyId")
} }
@@ -345,6 +368,10 @@ func (this *ReverseProxyDAO) UpdateReverseProxy(tx *dbs.Tx, reverseProxyId int64
op.MaxIdleConns = 0 op.MaxIdleConns = 0
} }
if len(proxyProtocolJSON) > 0 {
op.ProxyProtocol = proxyProtocolJSON
}
err = this.Save(tx, op) err = this.Save(tx, op)
if err != nil { if err != nil {
return err return err

View File

@@ -1,6 +1,6 @@
package models package models
// 反向代理配置 // ReverseProxy 反向代理配置
type ReverseProxy struct { type ReverseProxy struct {
Id uint32 `field:"id"` // ID Id uint32 `field:"id"` // ID
AdminId uint32 `field:"adminId"` // 管理员ID AdminId uint32 `field:"adminId"` // 管理员ID
@@ -23,6 +23,7 @@ type ReverseProxy struct {
IdleTimeout string `field:"idleTimeout"` // 空闲超时时间 IdleTimeout string `field:"idleTimeout"` // 空闲超时时间
MaxConns uint32 `field:"maxConns"` // 最大并发连接数 MaxConns uint32 `field:"maxConns"` // 最大并发连接数
MaxIdleConns uint32 `field:"maxIdleConns"` // 最大空闲连接数 MaxIdleConns uint32 `field:"maxIdleConns"` // 最大空闲连接数
ProxyProtocol string `field:"proxyProtocol"` // Proxy Protocol配置
} }
type ReverseProxyOperator struct { type ReverseProxyOperator struct {
@@ -47,6 +48,7 @@ type ReverseProxyOperator struct {
IdleTimeout interface{} // 空闲超时时间 IdleTimeout interface{} // 空闲超时时间
MaxConns interface{} // 最大并发连接数 MaxConns interface{} // 最大并发连接数
MaxIdleConns interface{} // 最大空闲连接数 MaxIdleConns interface{} // 最大空闲连接数
ProxyProtocol interface{} // Proxy Protocol配置
} }
func NewReverseProxyOperator() *ReverseProxyOperator { func NewReverseProxyOperator() *ReverseProxyOperator {

View File

@@ -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) 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)
if err != nil { if err != nil {
return nil, err return nil, err
} }