From c3b84b06ff16aa0ae280538b08ee4912c3d215a8 Mon Sep 17 00:00:00 2001 From: René 'Necoro' Neumann Date: Sun, 9 Jan 2022 23:11:23 +0100 Subject: Specify cookies in feed config to use in all HTTP requests. --- pkg/config/config.go | 22 ++++++++++++---------- pkg/config/yaml_test.go | 26 ++++++++++++++++++++++++++ 2 files changed, 38 insertions(+), 10 deletions(-) (limited to 'pkg') 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 -- cgit v1.2.3-70-g09d2