Browse Source

Set "Go-NEB" as the User-Agent on RSS feed polling

Some services, notably Reddit, basically force you to set a custom UA in order
to use their RSS feeds. All the common default non-browser UAs are HEAVILY
rate-limited such that you can't realistically use them.
kegan/rss-user-agent
Kegan Dougal 8 years ago
parent
commit
5b5de2dc4b
  1. 13
      src/github.com/matrix-org/go-neb/services/rssbot/rssbot.go

13
src/github.com/matrix-org/go-neb/services/rssbot/rssbot.go

@ -306,9 +306,20 @@ func itemToHTML(feed *gofeed.Feed, item gofeed.Item) matrix.HTMLMessage {
))
}
type userAgentRoundTripper struct {
Transport http.RoundTripper
}
func (rt userAgentRoundTripper) RoundTrip(req *http.Request) (*http.Response, error) {
req.Header.Set("User-Agent", "Go-NEB")
return rt.Transport.RoundTrip(req)
}
func init() {
lruCache := lrucache.New(1024*1024*20, 0) // 20 MB cache, no max-age
cachingClient = httpcache.NewTransport(lruCache).Client()
cachingClient = &http.Client{
Transport: userAgentRoundTripper{httpcache.NewTransport(lruCache)},
}
types.RegisterService(func(serviceID, serviceUserID, webhookEndpointURL string) types.Service {
r := &rssBotService{
id: serviceID,

Loading…
Cancel
Save