aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRené 'Necoro' Neumann <necoro@necoro.eu>2022-01-09 23:11:23 +0100
committerRené 'Necoro' Neumann <necoro@necoro.eu>2022-01-10 00:16:44 +0100
commitc3b84b06ff16aa0ae280538b08ee4912c3d215a8 (patch)
treec43aea6da3eeb10e696d794f7407cbae91920ed2
parent5b3f0f96b7e345a82f0d963ddef1dd4569465145 (diff)
downloadfeed2imap-go-c3b84b06ff16aa0ae280538b08ee4912c3d215a8.tar.gz
feed2imap-go-c3b84b06ff16aa0ae280538b08ee4912c3d215a8.tar.bz2
feed2imap-go-c3b84b06ff16aa0ae280538b08ee4912c3d215a8.zip
Specify cookies in feed config to use in all HTTP requests.
-rw-r--r--CHANGELOG.md1
-rw-r--r--config.yml.example6
-rw-r--r--pkg/config/config.go22
-rw-r--r--pkg/config/yaml_test.go26
4 files changed, 45 insertions, 10 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 6664bc1..c4aba03 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -8,6 +8,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Added
- [Issue #66](https://github.com/Necoro/feed2imap-go/issues/66): Allow specifying custom template files for HTML/Text output (configuration: `html-template`/`text-template`).
- [Issue #67](https://github.com/Necoro/feed2imap-go/issues/67): Support for fetching the linked article/website instead of using the body in the feed (configuration: `body: fetch`). This is especially useful when the feed only supplies links/teaser and not the full content.
+- Support for sending (authentication) cookies. Use case: Fetch things behind a paywall (esp. useful in combination with `body: fetch`)
### Fixed
- Panic on setting `body` on feed-level.
diff --git a/config.yml.example b/config.yml.example
index 90e5370..e933ade 100644
--- a/config.yml.example
+++ b/config.yml.example
@@ -71,6 +71,7 @@ options:
# - both: Use both
# - fetch: Ignore the body delivered by the feed and instead fetch the linked website.
# It may be advisable to set `include-images` to false in that mode to avoid unexpected large mails.
+ # To fetch something behind a paywall, you can specify authentication cookies with the `cookies` option.
body: default
# Disable a feed. Beats commenting ;)
disable: false
@@ -90,6 +91,11 @@ options:
# Items of a feed may be filtered. In general there is no real use in specifying this globally.
# For full information about this feature, visit https://github.com/Necoro/feed2imap-go/wiki/Detailed-Options.
item-filter: 'Author.Name != "Weirdo"'
+ # Specify cookies that are to be sent with every HTTP request to the configured targets.
+ # Mostly useful to fetch stuff behind a paywall by sending authentication cookie.
+ cookies:
+ - name: authentication
+ value: eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJhY2N...
## Feeds
# Each feed must have a name, and a URL or Exec argument. The name must be unique.
diff --git a/pkg/config/config.go b/pkg/config/config.go
index a580337..080699a 100644
--- a/pkg/config/config.go
+++ b/pkg/config/config.go
@@ -7,6 +7,7 @@ import (
"runtime"
"strings"
+ "github.com/Necoro/feed2imap-go/internal/http"
"github.com/Necoro/feed2imap-go/pkg/log"
"github.com/Necoro/feed2imap-go/pkg/util"
)
@@ -43,16 +44,17 @@ var DefaultGlobalOptions = GlobalOptions{
// Options are feed specific
// NB: Always specify a yaml name, as it is later used in processing
type Options struct {
- MinFreq int `yaml:"min-frequency"`
- InclImages bool `yaml:"include-images"`
- EmbedImages bool `yaml:"embed-images"`
- Disable bool `yaml:"disable"`
- IgnHash bool `yaml:"ignore-hash"`
- AlwaysNew bool `yaml:"always-new"`
- Reupload bool `yaml:"reupload-if-updated"`
- NoTLS bool `yaml:"tls-no-verify"`
- ItemFilter string `yaml:"item-filter"`
- Body Body `yaml:"body"`
+ MinFreq int `yaml:"min-frequency"`
+ InclImages bool `yaml:"include-images"`
+ EmbedImages bool `yaml:"embed-images"`
+ Disable bool `yaml:"disable"`
+ IgnHash bool `yaml:"ignore-hash"`
+ AlwaysNew bool `yaml:"always-new"`
+ Reupload bool `yaml:"reupload-if-updated"`
+ NoTLS bool `yaml:"tls-no-verify"`
+ ItemFilter string `yaml:"item-filter"`
+ Body Body `yaml:"body"`
+ Cookies []http.Cookie `yaml:"cookies"`
}
var DefaultFeedOptions = Options{
diff --git a/pkg/config/yaml_test.go b/pkg/config/yaml_test.go
index b422c38..7196693 100644
--- a/pkg/config/yaml_test.go
+++ b/pkg/config/yaml_test.go
@@ -7,6 +7,8 @@ import (
"github.com/google/go-cmp/cmp"
"gopkg.in/yaml.v3"
+
+ "github.com/Necoro/feed2imap-go/internal/http"
)
func t(s string) []string {
@@ -286,6 +288,30 @@ func TestUnmarshal(tst *testing.T) {
}()},
{name: "Known config with invalid feed-options",
inp: "options:\n max-frequency: 6", wantErr: true, config: config{}},
+ {name: "Nested config",
+ inp: `
+options:
+ cookies:
+ - name: foo
+ value: bar
+`, wantErr: false, config: func() config {
+ c := defaultConfig(nil, nil)
+ c.FeedOptions.Cookies = []http.Cookie{{Name: "foo", Value: "bar"}}
+ return c
+ }()},
+ {name: "Nested config; multiple",
+ inp: `
+options:
+ cookies:
+ - name: foo
+ value: bar
+ - name: baz
+ value: uff
+`, wantErr: false, config: func() config {
+ c := defaultConfig(nil, nil)
+ c.FeedOptions.Cookies = []http.Cookie{{"foo", "bar"}, {"baz", "uff"}}
+ return c
+ }()},
{name: "Config with feed",
inp: `
something: 1