repos / pico

pico services - prose.sh, pastes.sh, imgs.sh, feeds.sh, pgs.sh
git clone https://github.com/picosh/pico.git

commit
c4e2fa6
parent
adb600b
author
Eric Bower
date
2023-01-24 21:12:21 +0000 UTC
chore(feeds): http client cleanup
1 files changed,  +11, -11
M feeds/cron.go
+11, -11
 1@@ -20,17 +20,25 @@ import (
 2 
 3 var ErrNoRecentArticles = errors.New("no recent articles")
 4 
 5-var userAgent = "linux:feeds:v2"
 6-
 7 type UserAgentTransport struct {
 8 	http.RoundTripper
 9 }
10 
11 func (c *UserAgentTransport) RoundTrip(r *http.Request) (*http.Response, error) {
12+	userAgent := "linux:feeds:v2 (by /u/pico-sh)"
13 	r.Header.Set("User-Agent", userAgent)
14+	r.Header.Set("Accept", "*/*")
15 	return c.RoundTripper.RoundTrip(r)
16 }
17 
18+var httpClient = http.Client{
19+	Transport: &UserAgentTransport{
20+		&http.Transport{
21+			TLSClientConfig: &tls.Config{},
22+		},
23+	},
24+}
25+
26 type FeedItem struct {
27 	Title       string
28 	Link        string
29@@ -166,20 +174,12 @@ func (f *Fetcher) RunUser(user *db.User) error {
30 }
31 
32 func (f *Fetcher) ParseURL(fp *gofeed.Parser, url string) (*gofeed.Feed, error) {
33-	client := &http.Client{
34-		Transport: &UserAgentTransport{
35-			&http.Transport{
36-				TLSClientConfig: &tls.Config{},
37-			},
38-		},
39-	}
40-
41 	req, err := http.NewRequest("GET", url, nil)
42 	if err != nil {
43 		return nil, err
44 	}
45 
46-	resp, err := client.Do(req)
47+	resp, err := httpClient.Do(req)
48 	if err != nil {
49 		return nil, err
50 	}