aboutsummaryrefslogtreecommitdiff
path: root/internal/feed/parse.go
diff options
context:
space:
mode:
authorRené 'Necoro' Neumann <necoro@necoro.eu>2020-04-27 00:02:17 +0200
committerRené 'Necoro' Neumann <necoro@necoro.eu>2020-04-27 00:02:17 +0200
commitc2b5808ca6ba592507bf49512f8c90883f74ece0 (patch)
treed1726aade2e189a6207ea7f8496023ac40b0cdf2 /internal/feed/parse.go
parenta3d2087107312c1816adbc3d25882d36eb5b7d9d (diff)
downloadfeed2imap-go-c2b5808ca6ba592507bf49512f8c90883f74ece0.tar.gz
feed2imap-go-c2b5808ca6ba592507bf49512f8c90883f74ece0.tar.bz2
feed2imap-go-c2b5808ca6ba592507bf49512f8c90883f74ece0.zip
Add tls-no-verify option to disallow certificate checks.
Closes #3
Diffstat (limited to '')
-rw-r--r--internal/feed/parse.go30
1 files changed, 27 insertions, 3 deletions
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)