aboutsummaryrefslogtreecommitdiff
path: root/internal/feed
diff options
context:
space:
mode:
Diffstat (limited to 'internal/feed')
-rw-r--r--internal/feed/feed.go1
-rw-r--r--internal/feed/parse.go30
-rw-r--r--internal/feed/state.go2
3 files changed, 29 insertions, 4 deletions
diff --git a/internal/feed/feed.go b/internal/feed/feed.go
index 7b9f0de..f111cd6 100644
--- a/internal/feed/feed.go
+++ b/internal/feed/feed.go
@@ -15,6 +15,7 @@ type Feed struct {
feed *gofeed.Feed
items []feeditem
cached CachedFeed
+ Global config.GlobalOptions
}
type feedDescriptor struct {
diff --git a/internal/feed/parse.go b/internal/feed/parse.go
index c027bd3..cc55581 100644
--- a/internal/feed/parse.go
+++ b/internal/feed/parse.go
@@ -2,7 +2,9 @@ package feed
import (
ctxt "context"
+ "crypto/tls"
"fmt"
+ "net/http"
"time"
"github.com/mmcdole/gofeed"
@@ -10,14 +12,36 @@ import (
"github.com/Necoro/feed2imap-go/pkg/log"
)
-func context() (ctxt.Context, ctxt.CancelFunc) {
- return ctxt.WithTimeout(ctxt.Background(), 60*time.Second)
+// share HTTP clients
+var stdHTTPClient = &http.Client{Transport: http.DefaultTransport}
+var unsafeHTTPClient *http.Client
+
+func init() {
+ tlsConfig := &tls.Config{InsecureSkipVerify: true}
+ transport := http.DefaultTransport.(*http.Transport).Clone()
+ transport.TLSClientConfig = tlsConfig
+ unsafeHTTPClient = &http.Client{Transport: transport}
+}
+
+func context(timeout int) (ctxt.Context, ctxt.CancelFunc) {
+ return ctxt.WithTimeout(ctxt.Background(), time.Duration(timeout)*time.Second)
+}
+
+func setHTTPClient(parser *gofeed.Parser, disableTLS bool) {
+ if disableTLS {
+ parser.Client = unsafeHTTPClient
+ } else {
+ parser.Client = stdHTTPClient
+ }
}
func parseFeed(feed *Feed) error {
- ctx, cancel := context()
+ ctx, cancel := context(feed.Global.Timeout)
defer cancel()
+
fp := gofeed.NewParser()
+ setHTTPClient(fp, *feed.NoTLS)
+
parsedFeed, err := fp.ParseURLWithContext(feed.Url, ctx)
if err != nil {
return fmt.Errorf("while fetching %s from %s: %w", feed.Name, feed.Url, err)
diff --git a/internal/feed/state.go b/internal/feed/state.go
index 455602c..154fafd 100644
--- a/internal/feed/state.go
+++ b/internal/feed/state.go
@@ -104,7 +104,7 @@ func NewState(cfg *config.Config) *State {
}
for name, parsedFeed := range cfg.Feeds {
- state.feeds[name] = &Feed{Feed: parsedFeed}
+ state.feeds[name] = &Feed{Feed: parsedFeed, Global: cfg.GlobalOptions}
}
return &state