Skip to content
This repository was archived by the owner on Feb 13, 2025. It is now read-only.

Commit 56c1288

Browse files
authored
fix: empty proxy provider subscription info not omitted (#1759)
1 parent f4806b4 commit 56c1288

File tree

2 files changed

+9
-9
lines changed

2 files changed

+9
-9
lines changed

adapter/provider/provider.go

+2-4
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ func (pp *proxySetProvider) Initial() error {
137137
return err
138138
}
139139
if subscriptionInfo := cachefile.Cache().GetSubscriptionInfo(pp.Name()); subscriptionInfo != "" {
140-
pp.subscriptionInfo.Update(subscriptionInfo)
140+
pp.subscriptionInfo = NewSubscriptionInfo(subscriptionInfo)
141141
}
142142
pp.closeAllConnections()
143143
return nil
@@ -165,14 +165,12 @@ func NewProxySetProvider(name string, interval time.Duration, parser resource.Pa
165165
go hc.process()
166166
}
167167

168-
si := new(SubscriptionInfo)
169168
pd := &proxySetProvider{
170169
baseProvider: baseProvider{
171170
name: name,
172171
proxies: []C.Proxy{},
173172
healthCheck: hc,
174173
},
175-
subscriptionInfo: si,
176174
}
177175

178176
fetcher := resource.NewFetcher[[]C.Proxy](name, interval, vehicle, parser, proxiesOnUpdate(pd))
@@ -181,7 +179,7 @@ func NewProxySetProvider(name string, interval time.Duration, parser resource.Pa
181179
httpVehicle.SetInRead(func(resp *http.Response) {
182180
if subscriptionInfo := resp.Header.Get("subscription-userinfo"); subscriptionInfo != "" {
183181
cachefile.Cache().SetSubscriptionInfo(name, subscriptionInfo)
184-
si.Update(subscriptionInfo)
182+
pd.subscriptionInfo = NewSubscriptionInfo(subscriptionInfo)
185183
}
186184
})
187185
}

adapter/provider/subscription_info.go

+7-5
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,9 @@ type SubscriptionInfo struct {
1515
Expire int64
1616
}
1717

18-
func (info *SubscriptionInfo) Update(userinfo string) {
18+
func NewSubscriptionInfo(userinfo string) (si *SubscriptionInfo) {
1919
userinfo = strings.ReplaceAll(strings.ToLower(userinfo), " ", "")
20+
si = new(SubscriptionInfo)
2021

2122
for _, field := range strings.Split(userinfo, ";") {
2223
name, value, ok := strings.Cut(field, "=")
@@ -32,15 +33,16 @@ func (info *SubscriptionInfo) Update(userinfo string) {
3233

3334
switch name {
3435
case "upload":
35-
info.Upload = intValue
36+
si.Upload = intValue
3637
case "download":
37-
info.Download = intValue
38+
si.Download = intValue
3839
case "total":
39-
info.Total = intValue
40+
si.Total = intValue
4041
case "expire":
41-
info.Expire = intValue
42+
si.Expire = intValue
4243
}
4344
}
45+
return si
4446
}
4547

4648
func parseValue(value string) (int64, error) {

0 commit comments

Comments
 (0)