MCPcopy Index your code
hub / github.com/FunctionStream/function-stream / CacheExpires

Function CacheExpires

admin/client/client.go:602–628  ·  view source on GitHub ↗

CacheExpires helper function to determine remaining time before repeating a request.

(r *http.Response)

Source from the content-addressed store, hash-verified

600
601// CacheExpires helper function to determine remaining time before repeating a request.
602func 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
630func strlen(s string) int {
631 return utf8.RuneCountInString(s)

Callers

nothing calls this directly

Calls 2

parseCacheControlFunction · 0.85
GetMethod · 0.45

Tested by

no test coverage detected