Browse Source

Add User agent header for DiscoverLinks requests

master
Jan-Lukas Else 12 months ago
parent
commit
7599ebe944
2 changed files with 13 additions and 2 deletions
  1. +1
    -0
      feed.go
  2. +12
    -2
      main.go

+ 1
- 0
feed.go View File

@ -25,6 +25,7 @@ func LatestArticle(url string) (*Article, error) {
return nil, errors.New("failed to get json feed")
}
err = json.NewDecoder(resp.Body).Decode(&jsonFeed)
_ = resp.Body.Close()
if err != nil {
return nil, errors.New("failed to parse json feed")
}


+ 12
- 2
main.go View File

@ -89,8 +89,17 @@ func updateLastArticle(dirname string, feed string, url string, date string) err
}
func sendWebmentions(url string, blacklist []string) error {
client := webmention.New(nil)
discovered, err := client.DiscoverLinks(url, ".h-entry")
req, err := http.NewRequest(http.MethodGet, url, nil)
if err != nil {
return err
}
req.Header.Add("User-Agent", "WebmentionHelper")
resp, err := http.DefaultClient.Do(req)
if err != nil {
return err
}
discovered, err := webmention.DiscoverLinksFromReader(resp.Body, url, ".h-entry")
_ = resp.Body.Close()
if err != nil {
return err
}
@ -108,6 +117,7 @@ func sendWebmentions(url string, blacklist []string) error {
filtered = append(filtered, link)
}
}
client := webmention.New(nil)
for _, link := range filtered {
endpoint, err := client.DiscoverEndpoint(link)
if err != nil || len(endpoint) < 1 {


Loading…
Cancel
Save