mirror of
https://github.com/kataras/iris.git
synced 2025-01-23 18:51:03 +01:00
9f85b74fc9
Former-commit-id: da4f38eb9034daa49446df3ee529423b98f9b331
25 lines
494 B
Go
25 lines
494 B
Go
package entry
|
|
|
|
import (
|
|
"regexp"
|
|
"strconv"
|
|
)
|
|
|
|
var maxAgeExp = regexp.MustCompile(`maxage=(\d+)`)
|
|
|
|
// ParseMaxAge parses the max age from the receiver parameter, "cache-control" header
|
|
// returns seconds as int64
|
|
// if header not found or parse failed then it returns -1
|
|
func ParseMaxAge(header string) int64 {
|
|
if header == "" {
|
|
return -1
|
|
}
|
|
m := maxAgeExp.FindStringSubmatch(header)
|
|
if len(m) == 2 {
|
|
if v, err := strconv.Atoi(m[1]); err == nil {
|
|
return int64(v)
|
|
}
|
|
}
|
|
return -1
|
|
}
|