CacheExpires helper function to determine remaining time before repeating a request.
(r *http.Response)
| 600 | |
| 601 | // CacheExpires helper function to determine remaining time before repeating a request. |
| 602 | func CacheExpires(r *http.Response) time.Time { |
| 603 | // Figure out when the cache expires. |
| 604 | var expires time.Time |
| 605 | now, err := time.Parse(time.RFC1123, r.Header.Get("date")) |
| 606 | if err != nil { |
| 607 | return time.Now() |
| 608 | } |
| 609 | respCacheControl := parseCacheControl(r.Header) |
| 610 | |
| 611 | if maxAge, ok := respCacheControl["max-age"]; ok { |
| 612 | lifetime, err := time.ParseDuration(maxAge + "s") |
| 613 | if err != nil { |
| 614 | expires = now |
| 615 | } else { |
| 616 | expires = now.Add(lifetime) |
| 617 | } |
| 618 | } else { |
| 619 | expiresHeader := r.Header.Get("Expires") |
| 620 | if expiresHeader != "" { |
| 621 | expires, err = time.Parse(time.RFC1123, expiresHeader) |
| 622 | if err != nil { |
| 623 | expires = now |
| 624 | } |
| 625 | } |
| 626 | } |
| 627 | return expires |
| 628 | } |
| 629 | |
| 630 | func strlen(s string) int { |
| 631 | return utf8.RuneCountInString(s) |
nothing calls this directly
no test coverage detected