mirror of
				https://github.com/TeaOSLab/EdgeAPI.git
				synced 2025-11-04 16:00:24 +08:00 
			
		
		
		
	[反向代理]增加请求主机名类型选择
This commit is contained in:
		@@ -99,6 +99,7 @@ func (this *ReverseProxyDAO) ComposeReverseProxyConfig(reverseProxyId int64) (*s
 | 
				
			|||||||
	config := &serverconfigs.ReverseProxyConfig{}
 | 
						config := &serverconfigs.ReverseProxyConfig{}
 | 
				
			||||||
	config.Id = int64(reverseProxy.Id)
 | 
						config.Id = int64(reverseProxy.Id)
 | 
				
			||||||
	config.IsOn = reverseProxy.IsOn == 1
 | 
						config.IsOn = reverseProxy.IsOn == 1
 | 
				
			||||||
 | 
						config.RequestHostType = types.Int8(reverseProxy.RequestHostType)
 | 
				
			||||||
	config.RequestHost = reverseProxy.RequestHost
 | 
						config.RequestHost = reverseProxy.RequestHost
 | 
				
			||||||
	config.RequestURI = reverseProxy.RequestURI
 | 
						config.RequestURI = reverseProxy.RequestURI
 | 
				
			||||||
	config.StripPrefix = reverseProxy.StripPrefix
 | 
						config.StripPrefix = reverseProxy.StripPrefix
 | 
				
			||||||
@@ -223,13 +224,19 @@ func (this *ReverseProxyDAO) UpdateReverseProxyBackupOrigins(reverseProxyId int6
 | 
				
			|||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
// 修改是否启用
 | 
					// 修改是否启用
 | 
				
			||||||
func (this *ReverseProxyDAO) UpdateReverseProxy(reverseProxyId int64, requestHost string, requestURI string, stripPrefix string, autoFlush bool) error {
 | 
					func (this *ReverseProxyDAO) UpdateReverseProxy(reverseProxyId int64, requestHostType int8, requestHost string, requestURI string, stripPrefix string, autoFlush bool) error {
 | 
				
			||||||
	if reverseProxyId <= 0 {
 | 
						if reverseProxyId <= 0 {
 | 
				
			||||||
		return errors.New("invalid reverseProxyId")
 | 
							return errors.New("invalid reverseProxyId")
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	op := NewReverseProxyOperator()
 | 
						op := NewReverseProxyOperator()
 | 
				
			||||||
	op.Id = reverseProxyId
 | 
						op.Id = reverseProxyId
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						if requestHostType < 0 {
 | 
				
			||||||
 | 
							requestHostType = 0
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						op.RequestHostType = requestHostType
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	op.RequestHost = requestHost
 | 
						op.RequestHost = requestHost
 | 
				
			||||||
	op.RequestURI = requestURI
 | 
						op.RequestURI = requestURI
 | 
				
			||||||
	op.StripPrefix = stripPrefix
 | 
						op.StripPrefix = stripPrefix
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -2,37 +2,39 @@ package models
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
// 反向代理配置
 | 
					// 反向代理配置
 | 
				
			||||||
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
 | 
				
			||||||
	UserId         uint32 `field:"userId"`         // 用户ID
 | 
						UserId          uint32 `field:"userId"`          // 用户ID
 | 
				
			||||||
	TemplateId     uint32 `field:"templateId"`     // 模版ID
 | 
						TemplateId      uint32 `field:"templateId"`      // 模版ID
 | 
				
			||||||
	IsOn           uint8  `field:"isOn"`           // 是否启用
 | 
						IsOn            uint8  `field:"isOn"`            // 是否启用
 | 
				
			||||||
	Scheduling     string `field:"scheduling"`     // 调度算法
 | 
						Scheduling      string `field:"scheduling"`      // 调度算法
 | 
				
			||||||
	PrimaryOrigins string `field:"primaryOrigins"` // 主要源站
 | 
						PrimaryOrigins  string `field:"primaryOrigins"`  // 主要源站
 | 
				
			||||||
	BackupOrigins  string `field:"backupOrigins"`  // 备用源站
 | 
						BackupOrigins   string `field:"backupOrigins"`   // 备用源站
 | 
				
			||||||
	StripPrefix    string `field:"stripPrefix"`    // 去除URL前缀
 | 
						StripPrefix     string `field:"stripPrefix"`     // 去除URL前缀
 | 
				
			||||||
	RequestHost    string `field:"requestHost"`    // 请求Host
 | 
						RequestHostType uint8  `field:"requestHostType"` // 请求Host类型
 | 
				
			||||||
	RequestURI     string `field:"requestURI"`     // 请求URI
 | 
						RequestHost     string `field:"requestHost"`     // 请求Host
 | 
				
			||||||
	AutoFlush      uint8  `field:"autoFlush"`      // 是否自动刷新缓冲区
 | 
						RequestURI      string `field:"requestURI"`      // 请求URI
 | 
				
			||||||
	State          uint8  `field:"state"`          // 状态
 | 
						AutoFlush       uint8  `field:"autoFlush"`       // 是否自动刷新缓冲区
 | 
				
			||||||
	CreatedAt      uint64 `field:"createdAt"`      // 创建时间
 | 
						State           uint8  `field:"state"`           // 状态
 | 
				
			||||||
 | 
						CreatedAt       uint64 `field:"createdAt"`       // 创建时间
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
type ReverseProxyOperator struct {
 | 
					type ReverseProxyOperator struct {
 | 
				
			||||||
	Id             interface{} // ID
 | 
						Id              interface{} // ID
 | 
				
			||||||
	AdminId        interface{} // 管理员ID
 | 
						AdminId         interface{} // 管理员ID
 | 
				
			||||||
	UserId         interface{} // 用户ID
 | 
						UserId          interface{} // 用户ID
 | 
				
			||||||
	TemplateId     interface{} // 模版ID
 | 
						TemplateId      interface{} // 模版ID
 | 
				
			||||||
	IsOn           interface{} // 是否启用
 | 
						IsOn            interface{} // 是否启用
 | 
				
			||||||
	Scheduling     interface{} // 调度算法
 | 
						Scheduling      interface{} // 调度算法
 | 
				
			||||||
	PrimaryOrigins interface{} // 主要源站
 | 
						PrimaryOrigins  interface{} // 主要源站
 | 
				
			||||||
	BackupOrigins  interface{} // 备用源站
 | 
						BackupOrigins   interface{} // 备用源站
 | 
				
			||||||
	StripPrefix    interface{} // 去除URL前缀
 | 
						StripPrefix     interface{} // 去除URL前缀
 | 
				
			||||||
	RequestHost    interface{} // 请求Host
 | 
						RequestHostType interface{} // 请求Host类型
 | 
				
			||||||
	RequestURI     interface{} // 请求URI
 | 
						RequestHost     interface{} // 请求Host
 | 
				
			||||||
	AutoFlush      interface{} // 是否自动刷新缓冲区
 | 
						RequestURI      interface{} // 请求URI
 | 
				
			||||||
	State          interface{} // 状态
 | 
						AutoFlush       interface{} // 是否自动刷新缓冲区
 | 
				
			||||||
	CreatedAt      interface{} // 创建时间
 | 
						State           interface{} // 状态
 | 
				
			||||||
 | 
						CreatedAt       interface{} // 创建时间
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
func NewReverseProxyOperator() *ReverseProxyOperator {
 | 
					func NewReverseProxyOperator() *ReverseProxyOperator {
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -6,6 +6,7 @@ import (
 | 
				
			|||||||
	"github.com/TeaOSLab/EdgeAPI/internal/db/models"
 | 
						"github.com/TeaOSLab/EdgeAPI/internal/db/models"
 | 
				
			||||||
	rpcutils "github.com/TeaOSLab/EdgeAPI/internal/rpc/utils"
 | 
						rpcutils "github.com/TeaOSLab/EdgeAPI/internal/rpc/utils"
 | 
				
			||||||
	"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
 | 
						"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
 | 
				
			||||||
 | 
						"github.com/iwind/TeaGo/types"
 | 
				
			||||||
)
 | 
					)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
type ReverseProxyService struct {
 | 
					type ReverseProxyService struct {
 | 
				
			||||||
@@ -130,7 +131,7 @@ func (this *ReverseProxyService) UpdateReverseProxy(ctx context.Context, req *pb
 | 
				
			|||||||
		return nil, err
 | 
							return nil, err
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	err = models.SharedReverseProxyDAO.UpdateReverseProxy(req.ReverseProxyId, req.RequestHost, req.RequestURI, req.StripPrefix, req.AutoFlush)
 | 
						err = models.SharedReverseProxyDAO.UpdateReverseProxy(req.ReverseProxyId, types.Int8(req.RequestHostType), req.RequestHost, req.RequestURI, req.StripPrefix, req.AutoFlush)
 | 
				
			||||||
	if err != nil {
 | 
						if err != nil {
 | 
				
			||||||
		return nil, err
 | 
							return nil, err
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user