1
0
mirror of https://github.com/bestnite/sub2clash.git synced 2025-12-13 18:00:16 +00:00

feat: 返回头中增加订阅信息

This commit is contained in:
Chieh
2025-05-26 00:42:37 +00:00
parent 84c5a6e5f4
commit 0b8299f432
3 changed files with 65 additions and 0 deletions

View File

@@ -233,6 +233,21 @@ func BuildSub(clashType model.ClashType, query validator.SubValidator, template
return temp, nil
}
func fetchSubscriptionUserInfo(url string, userAgent string) (string, error) {
resp, err := common.Head(url, common.WithUserAgent(userAgent))
if err != nil {
logger.Logger.Debug("创建 HEAD 请求失败", zap.Error(err))
return "", err
}
defer resp.Body.Close()
if userInfo := resp.Header.Get("subscription-userinfo"); userInfo != "" {
return userInfo, nil
}
logger.Logger.Debug("目标 URL 未返回 subscription-userinfo 头", zap.Error(err))
return "", err
}
func MergeSubAndTemplate(temp *model.Subscription, sub *model.Subscription, igcg bool) {
var countryGroupNames []string

View File

@@ -25,6 +25,14 @@ func SubHandler(c *gin.Context) {
return
}
if len(query.Subs) == 1 {
userInfoHeader, err := fetchSubscriptionUserInfo(query.Subs[0], "clash")
if err != nil {
c.String(http.StatusInternalServerError, err.Error())
}
c.Header("subscription-userinfo", userInfoHeader)
}
if query.NodeListMode {
nodelist := model.NodeList{}
nodelist.Proxies = sub.Proxies