Use microformats module to parse <link> elements
This commit is contained in:
parent
55b279f363
commit
b291019093
|
@ -9,6 +9,8 @@ import (
|
||||||
|
|
||||||
"linkheader"
|
"linkheader"
|
||||||
"rss"
|
"rss"
|
||||||
|
|
||||||
|
"willnorris.com/go/microformats"
|
||||||
)
|
)
|
||||||
|
|
||||||
// GetHubURL finds the HubURL for topic
|
// GetHubURL finds the HubURL for topic
|
||||||
|
@ -51,7 +53,8 @@ func parseBodyLinks(client *http.Client, topic string) (string, error) {
|
||||||
}
|
}
|
||||||
defer resp.Body.Close()
|
defer resp.Body.Close()
|
||||||
|
|
||||||
if isFeedContentType(resp.Header.Get("Content-Type")) {
|
contentType := resp.Header.Get("Content-Type")
|
||||||
|
if isFeedContentType(contentType) {
|
||||||
body, err := ioutil.ReadAll(resp.Body)
|
body, err := ioutil.ReadAll(resp.Body)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return "", err
|
return "", err
|
||||||
|
@ -64,7 +67,16 @@ func parseBodyLinks(client *http.Client, topic string) (string, error) {
|
||||||
if feed.HubURL != "" {
|
if feed.HubURL != "" {
|
||||||
return feed.HubURL, nil
|
return feed.HubURL, nil
|
||||||
}
|
}
|
||||||
return "", fmt.Errorf("No hub url found in RSS feed")
|
return "", fmt.Errorf("No WebSub hub url found in the RSS feed")
|
||||||
|
} else if strings.HasPrefix(contentType, "text/html") {
|
||||||
|
topicURL, _ := url.Parse(topic)
|
||||||
|
md := microformats.Parse(resp.Body, topicURL)
|
||||||
|
if hubs, e := md.Rels["hub"]; e {
|
||||||
|
if len(hubs) >= 1 {
|
||||||
|
return hubs[0], nil
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return "", fmt.Errorf("No WebSub hub url found in HTML <link> elements")
|
||||||
}
|
}
|
||||||
|
|
||||||
return "", fmt.Errorf("Unknown content type of response: %s", resp.Header.Get("Content-Type"))
|
return "", fmt.Errorf("Unknown content type of response: %s", resp.Header.Get("Content-Type"))
|
||||||
|
|
Loading…
Reference in New Issue
Block a user