实现源站跟随功能

This commit is contained in:
GoEdgeLab
2022-03-14 15:42:45 +08:00
parent 76d12ea65a
commit 6533d39379
3 changed files with 8 additions and 3 deletions

View File

@@ -107,6 +107,7 @@ func (this *ReverseProxyDAO) ComposeReverseProxyConfig(tx *dbs.Tx, reverseProxyI
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
schedulingConfig := &serverconfigs.SchedulingConfig{} schedulingConfig := &serverconfigs.SchedulingConfig{}
if len(reverseProxy.Scheduling) > 0 && reverseProxy.Scheduling != "null" { if len(reverseProxy.Scheduling) > 0 && reverseProxy.Scheduling != "null" {
@@ -312,12 +313,13 @@ func (this *ReverseProxyDAO) UpdateReverseProxy(tx *dbs.Tx,
idleTimeout *shared.TimeDuration, idleTimeout *shared.TimeDuration,
maxConns int32, maxConns int32,
maxIdleConns int32, maxIdleConns int32,
proxyProtocolJSON []byte) error { proxyProtocolJSON []byte,
followRedirects bool) error {
if reverseProxyId <= 0 { if reverseProxyId <= 0 {
return errors.New("invalid reverseProxyId") return errors.New("invalid reverseProxyId")
} }
op := NewReverseProxyOperator() var op = NewReverseProxyOperator()
op.Id = reverseProxyId op.Id = reverseProxyId
if requestHostType < 0 { if requestHostType < 0 {
@@ -329,6 +331,7 @@ func (this *ReverseProxyDAO) UpdateReverseProxy(tx *dbs.Tx,
op.RequestURI = requestURI op.RequestURI = requestURI
op.StripPrefix = stripPrefix op.StripPrefix = stripPrefix
op.AutoFlush = autoFlush op.AutoFlush = autoFlush
op.FollowRedirects = followRedirects
if len(addHeaders) == 0 { if len(addHeaders) == 0 {
addHeaders = []string{} addHeaders = []string{}

View File

@@ -24,6 +24,7 @@ type ReverseProxy struct {
MaxConns uint32 `field:"maxConns"` // 最大并发连接数 MaxConns uint32 `field:"maxConns"` // 最大并发连接数
MaxIdleConns uint32 `field:"maxIdleConns"` // 最大空闲连接数 MaxIdleConns uint32 `field:"maxIdleConns"` // 最大空闲连接数
ProxyProtocol string `field:"proxyProtocol"` // Proxy Protocol配置 ProxyProtocol string `field:"proxyProtocol"` // Proxy Protocol配置
FollowRedirects uint8 `field:"followRedirects"` // 回源跟随
} }
type ReverseProxyOperator struct { type ReverseProxyOperator struct {
@@ -49,6 +50,7 @@ type ReverseProxyOperator struct {
MaxConns interface{} // 最大并发连接数 MaxConns interface{} // 最大并发连接数
MaxIdleConns interface{} // 最大空闲连接数 MaxIdleConns interface{} // 最大空闲连接数
ProxyProtocol interface{} // Proxy Protocol配置 ProxyProtocol interface{} // Proxy Protocol配置
FollowRedirects interface{} // 回源跟随
} }
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, req.ProxyProtocolJSON) 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)
if err != nil { if err != nil {
return nil, err return nil, err
} }