Skip to content

Commit 42bdbc9

Browse files
committed
fix: remove GODEBUG v2 and set UA
reddits bot detection is no longer happy with using GODEBUG to disabel http2, seems to be happy with enabled and setting proper UA related #77
1 parent 57cbe22 commit 42bdbc9

File tree

5 files changed

+28
-30
lines changed

5 files changed

+28
-30
lines changed

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,4 @@ dist/
99
.LSOverride
1010
._*
1111
github_token
12-
nom
12+
./nom

cmd/nom/main.go

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ var (
2727
)
2828

2929
func run(args []string, opts Options) error {
30-
cfg, err := config.New(opts.ConfigPath, opts.Pager, opts.PreviewFeeds)
30+
cfg, err := config.New(opts.ConfigPath, opts.Pager, opts.PreviewFeeds, version)
3131
if err != nil {
3232
return err
3333
}
@@ -67,10 +67,6 @@ func run(args []string, opts Options) error {
6767
}
6868

6969
func main() {
70-
// disable http2 client as causing issues with reddit rss feed requests
71-
// https://github.com/guyfedwards/nom/issues/7
72-
os.Setenv("GODEBUG", "http2client=0")
73-
7470
var opts Options
7571

7672
parser := flags.NewParser(&opts, flags.Default)

internal/commands/commands.go

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -161,25 +161,25 @@ func (c Commands) TUI() error {
161161
return fmt.Errorf("commands List: %w", err)
162162
}
163163

164-
var errorItems []ErrorItem
165-
// if no feeds in store, fetchAllFeeds, which will return previews
166-
if len(c.config.PreviewFeeds) > 0 {
167-
its, errorItems, err = c.fetchAllFeeds()
168-
if err != nil {
169-
return fmt.Errorf("[commands.go] TUI: %w", err)
170-
}
171-
// if no items, fetchAllFeeds and GetAllFeeds
172-
} else if len(its) == 0 {
173-
_, errorItems, err = c.fetchAllFeeds()
174-
if err != nil {
175-
return fmt.Errorf("[commands.go] TUI: %w", err)
176-
}
177-
// refetch for consistent data across calls
178-
its, err = c.GetAllFeeds()
179-
if err != nil {
180-
return fmt.Errorf("[commands.go] TUI: %w", err)
181-
}
182-
}
164+
var errorItems []ErrorItem
165+
// if no feeds in store, fetchAllFeeds, which will return previews
166+
if len(c.config.PreviewFeeds) > 0 {
167+
its, errorItems, err = c.fetchAllFeeds()
168+
if err != nil {
169+
return fmt.Errorf("[commands.go] TUI: %w", err)
170+
}
171+
// if no items, fetchAllFeeds and GetAllFeeds
172+
} else if len(its) == 0 {
173+
_, errorItems, err = c.fetchAllFeeds()
174+
if err != nil {
175+
return fmt.Errorf("[commands.go] TUI: %w", err)
176+
}
177+
// refetch for consistent data across calls
178+
its, err = c.GetAllFeeds()
179+
if err != nil {
180+
return fmt.Errorf("[commands.go] TUI: %w", err)
181+
}
182+
}
183183

184184
items := convertItems(its)
185185

@@ -257,7 +257,7 @@ func (c Commands) fetchAllFeeds() ([]store.Item, []ErrorItem, error) {
257257
for _, feed := range feeds {
258258
wg.Add(1)
259259

260-
go fetchFeed(ch, &wg, feed)
260+
go fetchFeed(ch, &wg, feed, c.config.Version)
261261
}
262262

263263
go func() {
@@ -336,10 +336,10 @@ func (c Commands) GetAllFeeds() ([]store.Item, error) {
336336
return items, nil
337337
}
338338

339-
func fetchFeed(ch chan FetchResultError, wg *sync.WaitGroup, feed config.Feed) {
339+
func fetchFeed(ch chan FetchResultError, wg *sync.WaitGroup, feed config.Feed, version string) {
340340
defer wg.Done()
341341

342-
r, err := rss.Fetch(feed)
342+
r, err := rss.Fetch(feed, version)
343343

344344
if err != nil {
345345
ch <- FetchResultError{res: rss.RSS{}, err: err, url: feed.URL}

internal/config/config.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ type Config struct {
4949
AutoRead bool `yaml:"autoread,omitempty"`
5050
ShowFavourites bool
5151
Openers []Opener `yaml:"openers,omitempty"`
52+
Version string
5253
}
5354

5455
func (c *Config) ToggleShowRead() {
@@ -59,7 +60,7 @@ func (c *Config) ToggleShowFavourites() {
5960
c.ShowFavourites = !c.ShowFavourites
6061
}
6162

62-
func New(configPath string, pager string, previewFeeds []string) (Config, error) {
63+
func New(configPath string, pager string, previewFeeds []string, version string) (Config, error) {
6364
var configDir string
6465

6566
if configPath == "" {

internal/rss/rss.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,9 @@ type RSS struct {
3131
Channel Channel `xml:"channel"`
3232
}
3333

34-
func Fetch(f config.Feed) (RSS, error) {
34+
func Fetch(f config.Feed, version string) (RSS, error) {
3535
fp := gofeed.NewParser()
36+
fp.UserAgent = fmt.Sprintf("nom/%s", version)
3637

3738
feed, err := fp.ParseURL(f.URL)
3839
if err != nil {

0 commit comments

Comments
 (0)