mirror of
https://github.com/miniflux/v2.git
synced 2025-06-27 16:36:00 +00:00
feat: use Cache-Control
max-age and Expires
headers to calculate next check
This commit is contained in:
parent
0af1a6e121
commit
c45b51d1f8
3 changed files with 110 additions and 2 deletions
|
@ -9,6 +9,7 @@ import (
|
|||
"fmt"
|
||||
"io"
|
||||
"log/slog"
|
||||
"math"
|
||||
"net"
|
||||
"net/http"
|
||||
"net/url"
|
||||
|
@ -53,6 +54,33 @@ func (r *ResponseHandler) ETag() string {
|
|||
return r.httpResponse.Header.Get("ETag")
|
||||
}
|
||||
|
||||
func (r *ResponseHandler) ExpiresInMinutes() int {
|
||||
expiresHeaderValue := r.httpResponse.Header.Get("Expires")
|
||||
if expiresHeaderValue != "" {
|
||||
t, err := time.Parse(time.RFC1123, expiresHeaderValue)
|
||||
if err == nil {
|
||||
return int(math.Ceil(time.Until(t).Minutes()))
|
||||
}
|
||||
}
|
||||
return 0
|
||||
}
|
||||
|
||||
func (r *ResponseHandler) CacheControlMaxAgeInMinutes() int {
|
||||
cacheControlHeaderValue := r.httpResponse.Header.Get("Cache-Control")
|
||||
if cacheControlHeaderValue != "" {
|
||||
for _, directive := range strings.Split(cacheControlHeaderValue, ",") {
|
||||
directive = strings.TrimSpace(directive)
|
||||
if strings.HasPrefix(directive, "max-age=") {
|
||||
maxAge, err := strconv.Atoi(strings.TrimPrefix(directive, "max-age="))
|
||||
if err == nil {
|
||||
return int(math.Ceil(float64(maxAge) / 60))
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return 0
|
||||
}
|
||||
|
||||
func (r *ResponseHandler) ParseRetryDelay() int {
|
||||
retryAfterHeaderValue := r.httpResponse.Header.Get("Retry-After")
|
||||
if retryAfterHeaderValue != "" {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue