mirror of
https://github.com/TeaOSLab/EdgeAPI.git
synced 2025-11-03 15:00:27 +08:00
创建反向代理时默认不自动重试50X/源站支持404内容自动重试其他源站
This commit is contained in:
@@ -110,6 +110,7 @@ func (this *ReverseProxyDAO) ComposeReverseProxyConfig(tx *dbs.Tx, reverseProxyI
|
||||
config.AutoFlush = reverseProxy.AutoFlush == 1
|
||||
config.FollowRedirects = reverseProxy.FollowRedirects == 1
|
||||
config.Retry50X = reverseProxy.Retry50X
|
||||
config.Retry40X = reverseProxy.Retry40X
|
||||
|
||||
var schedulingConfig = &serverconfigs.SchedulingConfig{}
|
||||
if IsNotNull(reverseProxy.Scheduling) {
|
||||
@@ -219,7 +220,8 @@ func (this *ReverseProxyDAO) CreateReverseProxy(tx *dbs.Tx, adminId int64, userI
|
||||
op.AdminId = adminId
|
||||
op.UserId = userId
|
||||
op.RequestHostType = serverconfigs.RequestHostTypeProxyServer
|
||||
op.Retry50X = true
|
||||
op.Retry50X = false
|
||||
op.Retry40X = false
|
||||
|
||||
defaultHeaders := []string{"X-Real-IP", "X-Forwarded-For", "X-Forwarded-By", "X-Forwarded-Host", "X-Forwarded-Proto"}
|
||||
defaultHeadersJSON, err := json.Marshal(defaultHeaders)
|
||||
@@ -428,7 +430,8 @@ func (this *ReverseProxyDAO) UpdateReverseProxy(tx *dbs.Tx,
|
||||
maxIdleConns int32,
|
||||
proxyProtocolJSON []byte,
|
||||
followRedirects bool,
|
||||
retry50X bool) error {
|
||||
retry50X bool,
|
||||
retry40X bool) error {
|
||||
if reverseProxyId <= 0 {
|
||||
return errors.New("invalid reverseProxyId")
|
||||
}
|
||||
@@ -494,6 +497,7 @@ func (this *ReverseProxyDAO) UpdateReverseProxy(tx *dbs.Tx,
|
||||
}
|
||||
|
||||
op.Retry50X = retry50X
|
||||
op.Retry40X = retry40X
|
||||
|
||||
err = this.Save(tx, op)
|
||||
if err != nil {
|
||||
|
||||
@@ -28,6 +28,7 @@ const (
|
||||
ReverseProxyField_ProxyProtocol dbs.FieldName = "proxyProtocol" // Proxy Protocol配置
|
||||
ReverseProxyField_FollowRedirects dbs.FieldName = "followRedirects" // 回源跟随
|
||||
ReverseProxyField_Retry50X dbs.FieldName = "retry50X" // 启用50X重试
|
||||
ReverseProxyField_Retry40X dbs.FieldName = "retry40X" // 启用40X重试
|
||||
)
|
||||
|
||||
// ReverseProxy 反向代理配置
|
||||
@@ -57,6 +58,7 @@ type ReverseProxy struct {
|
||||
ProxyProtocol dbs.JSON `field:"proxyProtocol"` // Proxy Protocol配置
|
||||
FollowRedirects uint8 `field:"followRedirects"` // 回源跟随
|
||||
Retry50X bool `field:"retry50X"` // 启用50X重试
|
||||
Retry40X bool `field:"retry40X"` // 启用40X重试
|
||||
}
|
||||
|
||||
type ReverseProxyOperator struct {
|
||||
@@ -85,6 +87,7 @@ type ReverseProxyOperator struct {
|
||||
ProxyProtocol any // Proxy Protocol配置
|
||||
FollowRedirects any // 回源跟随
|
||||
Retry50X any // 启用50X重试
|
||||
Retry40X any // 启用40X重试
|
||||
}
|
||||
|
||||
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.RequestHostExcludingPort, req.RequestURI, req.StripPrefix, req.AutoFlush, req.AddHeaders, connTimeout, readTimeout, idleTimeout, req.MaxConns, req.MaxIdleConns, req.ProxyProtocolJSON, req.FollowRedirects, req.Retry50X)
|
||||
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, req.Retry50X, req.Retry40X)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user