Skip to content

Commit 166af74

Browse files
PIKACHUIMCopilot
andauthored
Update server/middlewares/virtual_host.go
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> Signed-off-by: Pikachu Ren <40362270+PIKACHUIM@users.noreply.github.com>
1 parent a3b1029 commit 166af74

1 file changed

Lines changed: 2 additions & 41 deletions

File tree

server/middlewares/virtual_host.go

Lines changed: 2 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -1,43 +1,4 @@
11
package middlewares
22

3-
import (
4-
"strings"
5-
6-
"github.com/OpenListTeam/OpenList/v4/internal/conf"
7-
"github.com/OpenListTeam/OpenList/v4/internal/op"
8-
"github.com/OpenListTeam/OpenList/v4/server/common"
9-
"github.com/gin-gonic/gin"
10-
)
11-
12-
// VirtualHost 虚拟主机中间件,根据请求的 Host 头匹配虚拟主机配置
13-
func VirtualHost(c *gin.Context) {
14-
host := c.Request.Host
15-
// 去掉端口号
16-
domain := stripPort(host)
17-
if domain == "" {
18-
c.Next()
19-
return
20-
}
21-
22-
vhost, err := op.GetVirtualHostByDomain(domain)
23-
if err != nil || !vhost.Enabled {
24-
// 未找到匹配的虚拟主机或未启用,继续正常处理
25-
c.Next()
26-
return
27-
}
28-
29-
// 将虚拟主机信息存入请求上下文
30-
common.GinWithValue(c, conf.VirtualHostKey, vhost)
31-
c.Next()
32-
}
33-
34-
// stripPort 去掉 host 中的端口号
35-
func stripPort(host string) string {
36-
if idx := strings.LastIndex(host, ":"); idx != -1 {
37-
// 确保不是 IPv6 地址(IPv6 地址用 [] 包裹)
38-
if !strings.Contains(host, "[") {
39-
return host[:idx]
40-
}
41-
}
42-
return host
43-
}
3+
// Note: Virtual host resolution is handled by existing handlers/middlewares.
4+
// This file intentionally contains no additional code to avoid unused/dead middleware.

0 commit comments

Comments
 (0)