diff options
author | René 'Necoro' Neumann <necoro@necoro.eu> | 2020-05-04 15:31:46 +0200 |
---|---|---|
committer | René 'Necoro' Neumann <necoro@necoro.eu> | 2020-05-04 15:31:46 +0200 |
commit | e2322c799ae0a05ed2b7eb63bffebbe0b54b292f (patch) | |
tree | 9f72634c0f1525a514caa7d51e33c4dc8b5a137f /internal/feed/mail.go | |
parent | 44f53f5956216cdd52ad58d6e666013a8f202967 (diff) | |
download | feed2imap-go-e2322c799ae0a05ed2b7eb63bffebbe0b54b292f.tar.gz feed2imap-go-e2322c799ae0a05ed2b7eb63bffebbe0b54b292f.tar.bz2 feed2imap-go-e2322c799ae0a05ed2b7eb63bffebbe0b54b292f.zip |
Unify connection handling
Diffstat (limited to '')
-rw-r--r-- | internal/feed/mail.go | 12 |
1 files changed, 6 insertions, 6 deletions
diff --git a/internal/feed/mail.go b/internal/feed/mail.go index 3cb442e..0360e10 100644 --- a/internal/feed/mail.go +++ b/internal/feed/mail.go @@ -7,7 +7,6 @@ import ( "io" "io/ioutil" "mime" - "net/http" "net/url" "path" "strings" @@ -19,6 +18,7 @@ import ( "github.com/gabriel-vasile/mimetype" "github.com/Necoro/feed2imap-go/internal/feed/template" + "github.com/Necoro/feed2imap-go/internal/http" "github.com/Necoro/feed2imap-go/internal/msg" "github.com/Necoro/feed2imap-go/pkg/config" "github.com/Necoro/feed2imap-go/pkg/log" @@ -193,12 +193,12 @@ func (feed *Feed) Messages() (msg.Messages, error) { return mails, nil } -func getImage(src string, client *http.Client) ([]byte, string, error) { - resp, err := client.Get(src) +func getImage(src string, timeout int, disableTLS bool) ([]byte, string, error) { + resp, cancel, err := http.Get(src, timeout, disableTLS) if err != nil { return nil, "", fmt.Errorf("fetching from '%s': %w", src, err) } - defer resp.Body.Close() + defer cancel() img, err := ioutil.ReadAll(resp.Body) if err != nil { @@ -270,7 +270,7 @@ func (item *item) buildBody() { return } - srcUrl,err := url.Parse(src) + srcUrl, err := url.Parse(src) if err != nil { log.Errorf("Feed %s: Item %s: Error parsing URL '%s' embedded in item: %s", feed.Name, item.Item.Link, src, err) @@ -278,7 +278,7 @@ func (item *item) buildBody() { } imgUrl := feedUrl.ResolveReference(srcUrl) - img, mime, err := getImage(imgUrl.String(), httpClient(feed.NoTLS)) + img, mime, err := getImage(imgUrl.String(), feed.Global.Timeout, feed.NoTLS) if err != nil { log.Errorf("Feed %s: Item %s: Error fetching image: %s", feed.Name, item.Item.Link, err) |