mirror of
https://github.com/MetaCubeX/mihomo.git
synced 2026-03-04 12:57:31 +00:00
chore: change subscription-userinfo retrieval
This commit is contained in:
@@ -84,11 +84,12 @@ func NewFileVehicle(path string) *FileVehicle {
|
||||
}
|
||||
|
||||
type HTTPVehicle struct {
|
||||
url string
|
||||
path string
|
||||
proxy string
|
||||
header http.Header
|
||||
timeout time.Duration
|
||||
url string
|
||||
path string
|
||||
proxy string
|
||||
header http.Header
|
||||
timeout time.Duration
|
||||
provider types.ProxyProvider
|
||||
}
|
||||
|
||||
func (h *HTTPVehicle) Url() string {
|
||||
@@ -111,6 +112,10 @@ func (h *HTTPVehicle) Write(buf []byte) error {
|
||||
return safeWrite(h.path, buf)
|
||||
}
|
||||
|
||||
func (h *HTTPVehicle) SetProvider(provider types.ProxyProvider) {
|
||||
h.provider = provider
|
||||
}
|
||||
|
||||
func (h *HTTPVehicle) Read(ctx context.Context, oldHash utils.HashType) (buf []byte, hash utils.HashType, err error) {
|
||||
ctx, cancel := context.WithTimeout(ctx, h.timeout)
|
||||
defer cancel()
|
||||
@@ -133,6 +138,12 @@ func (h *HTTPVehicle) Read(ctx context.Context, oldHash utils.HashType) (buf []b
|
||||
return
|
||||
}
|
||||
defer resp.Body.Close()
|
||||
|
||||
if subscriptionInfo := resp.Header.Get("subscription-userinfo"); h.provider != nil && subscriptionInfo != "" {
|
||||
cachefile.Cache().SetSubscriptionInfo(h.provider.Name(), subscriptionInfo)
|
||||
h.provider.SetSubscriptionInfo(subscriptionInfo)
|
||||
}
|
||||
|
||||
if resp.StatusCode < 200 || resp.StatusCode > 299 {
|
||||
if setIfNoneMatch && resp.StatusCode == http.StatusNotModified {
|
||||
return nil, oldHash, nil
|
||||
|
||||
Reference in New Issue
Block a user