mirror of
https://github.com/miniflux/v2.git
synced 2025-07-22 17:18:37 +00:00
Add Prometheus exporter
This commit is contained in:
parent
16b7b3bc3e
commit
c394a61a4e
61 changed files with 809 additions and 96 deletions
|
@ -35,7 +35,7 @@ func Fetch(websiteURL, rules, userAgent string) (string, error) {
|
|||
return "", errors.New("scraper: unable to download web page")
|
||||
}
|
||||
|
||||
if !isWhitelistedContentType(response.ContentType) {
|
||||
if !isAllowedContentType(response.ContentType) {
|
||||
return "", fmt.Errorf("scraper: this resource is not a HTML document (%s)", response.ContentType)
|
||||
}
|
||||
|
||||
|
@ -95,7 +95,7 @@ func getPredefinedScraperRules(websiteURL string) string {
|
|||
return ""
|
||||
}
|
||||
|
||||
func isWhitelistedContentType(contentType string) bool {
|
||||
func isAllowedContentType(contentType string) bool {
|
||||
contentType = strings.ToLower(contentType)
|
||||
return strings.HasPrefix(contentType, "text/html") ||
|
||||
strings.HasPrefix(contentType, "application/xhtml+xml")
|
||||
|
|
|
@ -39,7 +39,7 @@ func TestWhitelistedContentTypes(t *testing.T) {
|
|||
}
|
||||
|
||||
for inputValue, expectedResult := range scenarios {
|
||||
actualResult := isWhitelistedContentType(inputValue)
|
||||
actualResult := isAllowedContentType(inputValue)
|
||||
if actualResult != expectedResult {
|
||||
t.Errorf(`Unexpected result for content type whitelist, got "%v" instead of "%v"`, actualResult, expectedResult)
|
||||
}
|
||||
|
@ -47,10 +47,10 @@ func TestWhitelistedContentTypes(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestSelectorRules(t *testing.T) {
|
||||
var ruleTestCases = map[string]string {
|
||||
"img.html": "article > img",
|
||||
"iframe.html": "article > iframe",
|
||||
"p.html": "article > p",
|
||||
var ruleTestCases = map[string]string{
|
||||
"img.html": "article > img",
|
||||
"iframe.html": "article > iframe",
|
||||
"p.html": "article > p",
|
||||
}
|
||||
|
||||
for filename, rule := range ruleTestCases {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue