3 +--------------------------------------------------------------------+
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2018 |
7 +--------------------------------------------------------------------+
8 | This file is a part of CiviCRM. |
10 | CiviCRM is free software; you can copy, modify, and distribute it |
11 | under the terms of the GNU Affero General Public License |
12 | Version 3, 19 November 2007 and the CiviCRM Licensing Exception. |
14 | CiviCRM is distributed in the hope that it will be useful, but |
15 | WITHOUT ANY WARRANTY; without even the implied warranty of |
16 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
17 | See the GNU Affero General Public License for more details. |
19 | You should have received a copy of the GNU Affero General Public |
20 | License and the CiviCRM Licensing Exception along |
21 | with this program; if not, contact CiviCRM LLC |
22 | at info[AT]civicrm[DOT]org. If you have questions about the |
23 | GNU Affero General Public License or the licensing of CiviCRM, |
24 | see the CiviCRM license FAQ at http://civicrm.org/licensing |
25 +--------------------------------------------------------------------+
30 * @package CiviCRM_Hook
31 * @copyright CiviCRM LLC (c) 2004-2018
33 class CRM_Utils_Http
{
36 * Parse the expiration time from a series of HTTP headers.
38 * @param array $headers
40 * Expiration tme as seconds since epoch, or NULL if not cacheable.
42 public static function parseExpiration($headers) {
43 $headers = CRM_Utils_Array
::rekey($headers, function ($k, $v) {
44 return strtolower($k);
47 if (!empty($headers['cache-control'])) {
48 $cc = self
::parseCacheControl($headers['cache-control']);
49 if ($cc['max-age'] && is_numeric($cc['max-age'])) {
50 return CRM_Utils_Time
::getTimeRaw() +
$cc['max-age'];
58 * @param string $value
59 * Ex: "max-age=86400, public".
61 * Ex: Array("max-age"=>86400, "public"=>1).
63 public static function parseCacheControl($value) {
66 $parts = preg_split('/, */', $value);
67 foreach ($parts as $part) {
68 if (strpos($part, '=') !== FALSE) {
69 list ($key, $value) = explode('=', $part, 2);
70 $result[$key] = $value;
73 $result[$part] = TRUE;