mirror of
https://github.com/TeaOSLab/EdgeAPI.git
synced 2025-11-10 04:20:26 +08:00
支持PROXY Protocol
This commit is contained in:
@@ -190,6 +190,16 @@ func (this *ReverseProxyDAO) ComposeReverseProxyConfig(tx *dbs.Tx, reverseProxyI
|
||||
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
|
||||
|
||||
return config, nil
|
||||
@@ -286,7 +296,20 @@ func (this *ReverseProxyDAO) UpdateReverseProxyBackupOrigins(tx *dbs.Tx, reverse
|
||||
}
|
||||
|
||||
// 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 {
|
||||
return errors.New("invalid reverseProxyId")
|
||||
}
|
||||
@@ -345,6 +368,10 @@ func (this *ReverseProxyDAO) UpdateReverseProxy(tx *dbs.Tx, reverseProxyId int64
|
||||
op.MaxIdleConns = 0
|
||||
}
|
||||
|
||||
if len(proxyProtocolJSON) > 0 {
|
||||
op.ProxyProtocol = proxyProtocolJSON
|
||||
}
|
||||
|
||||
err = this.Save(tx, op)
|
||||
if err != nil {
|
||||
return err
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
package models
|
||||
|
||||
// 反向代理配置
|
||||
// ReverseProxy 反向代理配置
|
||||
type ReverseProxy struct {
|
||||
Id uint32 `field:"id"` // ID
|
||||
AdminId uint32 `field:"adminId"` // 管理员ID
|
||||
@@ -23,6 +23,7 @@ type ReverseProxy struct {
|
||||
IdleTimeout string `field:"idleTimeout"` // 空闲超时时间
|
||||
MaxConns uint32 `field:"maxConns"` // 最大并发连接数
|
||||
MaxIdleConns uint32 `field:"maxIdleConns"` // 最大空闲连接数
|
||||
ProxyProtocol string `field:"proxyProtocol"` // Proxy Protocol配置
|
||||
}
|
||||
|
||||
type ReverseProxyOperator struct {
|
||||
@@ -47,6 +48,7 @@ type ReverseProxyOperator struct {
|
||||
IdleTimeout interface{} // 空闲超时时间
|
||||
MaxConns interface{} // 最大并发连接数
|
||||
MaxIdleConns interface{} // 最大空闲连接数
|
||||
ProxyProtocol interface{} // Proxy Protocol配置
|
||||
}
|
||||
|
||||
func NewReverseProxyOperator() *ReverseProxyOperator {
|
||||
|
||||
@@ -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 {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user