Skip to content

Commit

Permalink
chore: Make SubScriptioninfo query also follow Proxy
Browse files Browse the repository at this point in the history
  • Loading branch information
xishang0128 committed Apr 11, 2024
1 parent 91a7ffa commit e3b69b8
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 4 deletions.
8 changes: 4 additions & 4 deletions adapter/provider/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -124,17 +124,17 @@ func (pp *proxySetProvider) getSubscriptionInfo() {
go func() {
ctx, cancel := context.WithTimeout(context.Background(), time.Second*90)
defer cancel()
resp, err := mihomoHttp.HttpRequest(ctx, pp.Vehicle().(*resource.HTTPVehicle).Url(),
http.MethodGet, http.Header{"User-Agent": {C.UA}}, nil)
resp, err := mihomoHttp.HttpRequestWithProxy(ctx, pp.Vehicle().(*resource.HTTPVehicle).Url(),
http.MethodGet, http.Header{"User-Agent": {C.UA}}, nil, pp.Vehicle().Proxy())
if err != nil {
return
}
defer resp.Body.Close()

userInfoStr := strings.TrimSpace(resp.Header.Get("subscription-userinfo"))
if userInfoStr == "" {
resp2, err := mihomoHttp.HttpRequest(ctx, pp.Vehicle().(*resource.HTTPVehicle).Url(),
http.MethodGet, http.Header{"User-Agent": {"Quantumultx"}}, nil)
resp2, err := mihomoHttp.HttpRequestWithProxy(ctx, pp.Vehicle().(*resource.HTTPVehicle).Url(),
http.MethodGet, http.Header{"User-Agent": {"Quantumultx"}}, nil, pp.Vehicle().Proxy())
if err != nil {
return
}
Expand Down
8 changes: 8 additions & 0 deletions component/resource/vehicle.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,10 @@ func (f *FileVehicle) Read() ([]byte, error) {
return os.ReadFile(f.path)
}

func (f *FileVehicle) Proxy() string {
return ""
}

func NewFileVehicle(path string) *FileVehicle {
return &FileVehicle{path: path}
}
Expand All @@ -51,6 +55,10 @@ func (h *HTTPVehicle) Path() string {
return h.path
}

func (h *HTTPVehicle) Proxy() string {
return h.proxy
}

func (h *HTTPVehicle) Read() ([]byte, error) {
ctx, cancel := context.WithTimeout(context.Background(), time.Second*20)
defer cancel()
Expand Down
1 change: 1 addition & 0 deletions constant/provider/interface.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ func (v VehicleType) String() string {
type Vehicle interface {
Read() ([]byte, error)
Path() string
Proxy() string
Type() VehicleType
}

Expand Down

0 comments on commit e3b69b8

Please sign in to comment.