File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 11package 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.
You can’t perform that action at this time.
0 commit comments