aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--internal/feed/feed.go1
-rw-r--r--internal/feed/parse.go30
-rw-r--r--internal/feed/state.go2
-rw-r--r--pkg/config/config.go5
4 files changed, 34 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
diff --git a/pkg/config/config.go b/pkg/config/config.go
index 37dffcf..885b80e 100644
--- a/pkg/config/config.go
+++ b/pkg/config/config.go
@@ -40,6 +40,7 @@ type Options struct {
Disable *bool `yaml:"disable"`
IgnHash *bool `yaml:"ignore-hash"`
AlwaysNew *bool `yaml:"always-new"`
+ NoTLS *bool `yaml:"tls-no-verify"`
}
func (opt *Options) mergeFrom(other Options) {
@@ -58,6 +59,9 @@ func (opt *Options) mergeFrom(other Options) {
if opt.Disable == nil {
opt.Disable = other.Disable
}
+ if opt.NoTLS == nil {
+ opt.NoTLS = other.NoTLS
+ }
}
// Default feed options
@@ -72,6 +76,7 @@ func init() {
IgnHash: &fal,
AlwaysNew: &fal,
Disable: &fal,
+ NoTLS: &fal,
}
}