mirror of
				https://github.com/bufanyun/hotgo.git
				synced 2025-11-04 16:23:43 +08:00 
			
		
		
		
	fix: 兼容hostname+host请求头
This commit is contained in:
		@@ -45,7 +45,12 @@ func (c *cSite) Config(ctx context.Context, _ *common.SiteConfigReq) (res *commo
 | 
			
		||||
 | 
			
		||||
func (c *cSite) getWsAddr(ctx context.Context, request *ghttp.Request) string {
 | 
			
		||||
	// 如果是本地IP访问,则认为是调试模式,走实际请求地址,否则走配置中的地址
 | 
			
		||||
	ip := ghttp.RequestFromCtx(ctx).GetHost()
 | 
			
		||||
	// 尝试读取hostname,兼容本地运行模式
 | 
			
		||||
	ip := ghttp.RequestFromCtx(ctx).GetHeader("hostname")
 | 
			
		||||
	if len(ip) == 0 {
 | 
			
		||||
		ip = ghttp.RequestFromCtx(ctx).GetHost()
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	if validate.IsLocalIPAddr(ip) {
 | 
			
		||||
		return "ws://" + ip + ":" + gstr.StrEx(request.Host, ":") + g.Cfg().MustGet(ctx, "router.websocket.prefix").String()
 | 
			
		||||
	}
 | 
			
		||||
@@ -59,7 +64,12 @@ func (c *cSite) getWsAddr(ctx context.Context, request *ghttp.Request) string {
 | 
			
		||||
 | 
			
		||||
func (c *cSite) getDomain(ctx context.Context, request *ghttp.Request) string {
 | 
			
		||||
	// 如果是本地IP访问,则认为是调试模式,走实际请求地址,否则走配置中的地址
 | 
			
		||||
	ip := request.GetHost()
 | 
			
		||||
	// 尝试读取hostname,兼容本地运行模式
 | 
			
		||||
	ip := ghttp.RequestFromCtx(ctx).GetHeader("hostname")
 | 
			
		||||
	if len(ip) == 0 {
 | 
			
		||||
		ip = ghttp.RequestFromCtx(ctx).GetHost()
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	if validate.IsLocalIPAddr(ip) {
 | 
			
		||||
		return "http://" + ip + ":" + gstr.StrEx(request.Host, ":")
 | 
			
		||||
	}
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user