6 * Parse the expiration time from a series of HTTP headers.
8 * @param array $headers
10 * Expiration tme as seconds since epoch, or NULL if not cacheable.
12 public static function parseExpiration($headers) {
13 $headers = CRM_Utils_Array
::rekey($headers, function ($k, $v) {
14 return strtolower($k);
17 if (!empty($headers['cache-control'])) {
18 $cc = self
::parseCacheControl($headers['cache-control']);
19 if ($cc['max-age'] && is_numeric($cc['max-age'])) {
20 return CRM_Utils_Time
::getTimeRaw() +
$cc['max-age'];
28 * @param string $value
29 * Ex: "max-age=86400, public".
31 * Ex: Array("max-age"=>86400, "public"=>1).
33 public static function parseCacheControl($value) {
36 $parts = preg_split('/, */', $value);
37 foreach ($parts as $part) {
38 if (strpos($part, '=') !== FALSE) {
39 list ($key, $value) = explode('=', $part, 2);
40 $result[$key] = $value;
43 $result[$part] = TRUE;