Skip to content

Commit

Permalink
Update alist.go
Browse files Browse the repository at this point in the history
  • Loading branch information
Sakura-Byte committed Feb 3, 2025
1 parent 34ad6e2 commit 0aa9ed6
Showing 1 changed file with 10 additions and 9 deletions.
19 changes: 10 additions & 9 deletions backend/alist/alist.go
Original file line number Diff line number Diff line change
Expand Up @@ -761,13 +761,6 @@ func (f *Fs) invalidateCache(dir string) {
delete(f.fileListCache, dir)
}

// setCommonHeaders sets headers on an HTTP request.
func (f *Fs) setCommonHeaders(req *http.Request, headers map[string]string) {
for key, value := range headers {
req.Header.Set(key, value)
}
}

// fetchCloudflare contacts the CF server to obtain cookies (and optionally a user agent)
// for the given targetURL.
func (f *Fs) fetchCloudflare(ctx context.Context, targetURL string) error {
Expand All @@ -776,7 +769,11 @@ func (f *Fs) fetchCloudflare(ctx context.Context, targetURL string) error {
if err != nil {
return err
}
defer resp.Body.Close()
defer func() {
if err := resp.Body.Close(); err != nil {
fs.Errorf(ctx, "Failed to close response body in fetchCloudflare: %v", err)
}
}()

// Decode the JSON response into a map.
// For example, the response might be: {"cf_clearance": "cookie_value"}
Expand Down Expand Up @@ -834,7 +831,11 @@ func (f *Fs) fetchUserAgent(ctx context.Context) error {
if err != nil {
return err
}
defer resp.Body.Close()
defer func() {
if err := resp.Body.Close(); err != nil {
fs.Errorf(ctx, "Failed to close response body in fetchUserAgent: %v", err)
}
}()
bodyBytes, err := io.ReadAll(resp.Body)
if err != nil {
return err
Expand Down

0 comments on commit 0aa9ed6

Please sign in to comment.