3 +--------------------------------------------------------------------+
4 | Copyright CiviCRM LLC. All rights reserved. |
6 | This work is published under the GNU AGPLv3 license with some |
7 | permitted exceptions and without any warranty. For full license |
8 | and copyright information, see https://civicrm.org/licensing |
9 +--------------------------------------------------------------------+
14 * @package CiviCRM_Hook
15 * @copyright CiviCRM LLC https://civicrm.org/licensing
17 class CRM_Utils_Http
{
20 * Parse the expiration time from a series of HTTP headers.
22 * @param array $headers
24 * Expiration tme as seconds since epoch, or NULL if not cacheable.
26 public static function parseExpiration($headers) {
27 $headers = CRM_Utils_Array
::rekey($headers, function ($k, $v) {
28 return strtolower($k);
31 if (!empty($headers['cache-control'])) {
32 $cc = self
::parseCacheControl($headers['cache-control']);
33 if ($cc['max-age'] && is_numeric($cc['max-age'])) {
34 return CRM_Utils_Time
::getTimeRaw() +
$cc['max-age'];
42 * @param string $value
43 * Ex: "max-age=86400, public".
45 * Ex: Array("max-age"=>86400, "public"=>1).
47 public static function parseCacheControl($value) {
50 $parts = preg_split('/, */', $value);
51 foreach ($parts as $part) {
52 if (strpos($part, '=') !== FALSE) {
53 list ($key, $value) = explode('=', $part, 2);
54 $result[$key] = $value;
57 $result[$part] = TRUE;