17 require_once SQ_ATTRIBUTES_PATH.
'/serialise/serialise.inc';
18 require_once SQ_ATTRIBUTES_PATH.
'/option_list/option_list.inc';
34 private $_methods = Array(
42 private $_authentication_types = Array(
44 'HTTP_Basic' =>
'HTTP Basic',
45 'Matrix' =>
'Matrix Cookie Passthrough',
49 private $_cache_options = Array(
50 'NEVER' =>
'Never Cache',
51 'DEFAULT' =>
'Use Default Expiry',
52 'HTTP' =>
'Use HTTP Expiry Headers',
55 private $_document_encoding = Array(
56 'Auto' =>
'Auto Detect',
57 'ISO-8859-1' =>
'ISO-8859-1',
58 'ISO-8859-15' =>
'ISO-8859-15',
65 'BIG5-HKSCS' =>
'BIG5-HKSCS',
66 'Shift_JIS' =>
'Shift_JIS',
73 protected $_res = Array();
74 protected $_config = Array();
75 private $_keyword_replacements = Array();
76 private $_urls_to_request = Array();
77 private $_headers = Array();
78 private $_last_header = FALSE;
89 parent::__construct($attribute, $value);
103 public function paint($prefix, $read_only = FALSE)
105 $prefix = str_replace(
':',
'_', $prefix);
106 $current_value = @unserialize($this->value);
109 if (!is_array($current_value)) $current_value = Array();
110 if (!isset($current_value[
'urls'])) $current_value[
'urls'] = Array();
111 if (!isset($current_value[
'method'])) $current_value[
'method'] =
'GET';
112 if (!isset($current_value[
'timeout'])) $current_value[
'timeout'] = 10;
113 if (!isset($current_value[
'follow_redirect'])) $current_value[
'follow_redirect'] = TRUE;
114 if (!isset($current_value[
'disable_ssl_verify'])) $current_value[
'disable_ssl_verify'] = FALSE;
115 if (!isset($current_value[
'cache_options'])) $current_value[
'cache_options'] =
'HTTP';
116 if (!isset($current_value[
'cache_post_requests'])) $current_value[
'cache_post_requests'] = FALSE;
117 if (!isset($current_value[
'default_cache_expiry'])) $current_value[
'default_cache_expiry'] = 60;
118 if (!isset($current_value[
'authentication_type'])) $current_value[
'authentication_type'] =
'NONE';
119 if (!isset($current_value[
'http_auth_options'])) $current_value[
'http_auth_options'] = Array(
'username' =>
'',
'password' =>
'');
120 if (!isset($current_value[
'request_headers'])) $current_value[
'request_headers'] = Array();
121 if (!isset($current_value[
'request_body'])) $current_value[
'request_body'] =
'';
122 if (!isset($current_value[
'convert_to_utf8'])) $current_value[
'convert_to_utf8'] = FALSE;
123 if (!isset($current_value[
'append_get_vars'])) $current_value[
'append_get_vars'] = FALSE;
124 if (!isset($current_value[
'forward_user_keys'])) $current_value[
'forward_user_keys'] = FALSE;
125 if (!isset($current_value[
'document_encoding'])) $current_value[
'document_encoding'] =
'Auto';
126 if (!isset($current_value[
'run_test'])) $current_value[
'run_test'] = FALSE;
127 if (!isset($current_value[
'oauth_asset'][
'assetid'])) $current_value[
'oauth_asset'] = Array(
'assetid' =>
'0',
'url' =>
'',
'linkid' =>
'');
130 <table border=
"0" class=
"sq-backend-table">
132 <th width=
"20%"><?php echo translate(
'http_request_method'); ?></th>
136 echo htmlspecialchars($current_value[
'method']);
138 combo_box($prefix.
'_method', $this->_methods, FALSE, $current_value[
'method']);
144 if ($current_value[
'method'] ==
'POST') {
147 <th><?php echo translate(
'http_request_cache_post_requests'); ?></th>
151 echo htmlspecialchars($current_value[
'cache_post_requests'] ?
'Yes' :
'No');
153 check_box($prefix.
'_cache_post_requests', 1, $current_value[
'cache_post_requests']);
162 <th><?php echo translate(
'http_request_urls'); ?></th>
166 $ol->value = implode($ol->delimiter, $current_value[
'urls']);
167 $ol->setEditParam(
'width',
'70');
168 $ol->paint($prefix.
'_urls', $read_only);
173 <th><?php echo translate(
'http_request_timeout'); ?></th>
177 echo htmlspecialchars($current_value[
'timeout']);
179 text_box($prefix.
'_timeout', $current_value[
'timeout'], 4);
185 <th><?php echo translate(
'http_request_follow_redirect'); ?></th>
189 echo htmlspecialchars($current_value[
'follow_redirect'] ?
'Yes' :
'No');
191 check_box($prefix.
'_follow_redirect', 1, $current_value[
'follow_redirect']);
197 <th><?php echo translate(
'http_request_disable_ssl_verify'); ?></th>
201 echo htmlspecialchars($current_value[
'disable_ssl_verify'] ?
'Yes' :
'No');
203 check_box($prefix.
'_disable_ssl_verify', 1, $current_value[
'disable_ssl_verify']);
210 <th><?php echo translate(
'http_request_cache_options'); ?></th>
214 echo htmlspecialchars($this->_cache_options[$current_value[
'cache_options']]);
216 combo_box($prefix.
'_cache_options', $this->_cache_options, FALSE, $current_value[
'cache_options']);
223 <th><?php echo translate(
'http_request_default_cache_expiry'); ?></th>
227 echo htmlspecialchars($current_value[
'default_cache_expiry']);
229 text_box($prefix.
'_default_cache_expiry', $current_value[
'default_cache_expiry'], 7);
235 <th><?php echo translate(
'http_request_authentication_type'); ?></th>
239 echo htmlspecialchars($this->_authentication_types[$current_value[
'authentication_type']]);
241 combo_box($prefix.
'_authentication_type', $this->_authentication_types, FALSE, $current_value[
'authentication_type']);
243 switch ($current_value[
'authentication_type']) {
248 <th><?php echo translate(
'username'); ?></th>
251 text_box($prefix.
'_http_auth_user', $current_value[
'http_auth_options'][
'username'],
'',
'',
'autocomplete="off"');
256 <th><?php echo translate(
'password'); ?></th>
259 password_box($prefix.
'_http_auth_pass', $current_value[
'http_auth_options'][
'password'],
'',
'',
'autocomplete="off"');
268 <span>Note: This requires the global setting <strong>Allow IP Change</strong></span>
273 'page_rest_resource_oauth_session' =>
'D',
274 'page_rest_resource_oauth_two_legged' =>
'D',
279 <th><?php translate(
'oauth_asset'); ?></th>
282 asset_finder($prefix.
'_oauth_asset', $current_value[
'oauth_asset'][
'assetid'], $type_codes);
295 <th><?php echo translate(
'http_request_request_headers'); ?></th>
299 $hl->value = implode($hl->delimiter, $current_value[
'request_headers']);
300 $hl->setEditParam(
'width',
'60');
301 $hl->paint($prefix.
'_request_headers', $read_only);
306 if (($current_value[
'method'] ==
'POST') || ($current_value[
'method'] ==
'PUT')) {
309 <th><?php echo translate(
'http_request_request_body'); ?></th>
313 echo htmlspecialchars($current_value[
'request_body']);
315 text_area($prefix.
'_request_body', $current_value[
'request_body'], 70, 20, 0,
'style="font-family: monospace;"');
322 hidden_field($prefix.
'_request_body', $current_value[
'request_body']);
326 <th><?php echo translate(
'http_request_convert_to_utf8'); ?></th>
330 echo $current_value[
'convert_to_utf8'] ?
'Yes' :
'No';
332 check_box($prefix.
'_convert_to_utf8', 1, $current_value[
'convert_to_utf8']);
338 if ($current_value[
'convert_to_utf8'] == TRUE) {
341 <th><?php echo translate(
'http_request_document_encoding'); ?></th>
345 echo $this->_document_encoding[$current_value[
'document_encoding']];
347 echo combo_box($prefix.
'_document_encoding', $this->_document_encoding, FALSE, $current_value[
'document_encoding']);
356 <th><?php echo translate(
'http_request_append_get_vars'); ?></th>
360 echo $current_value[
'append_get_vars'] ?
'Yes' :
'No';
362 check_box($prefix.
'_append_get_vars', 1, $current_value[
'append_get_vars']);
368 <th><?php echo translate(
'http_request_forward_user_keys'); ?></th>
372 echo $current_value[
'forward_user_keys'] ?
'Yes' :
'No';
374 check_box($prefix.
'_forward_user_keys', 1, $current_value[
'forward_user_keys']);
380 <th><?php echo translate(
'http_request_run_test'); ?></th>
384 echo $current_value[
'run_test'] ?
'Yes' :
'No';
386 check_box($prefix.
'_run_test', 1, 0);
389 if ($current_value[
'run_test'] == 1) {
392 if (!empty($res) || $res[
'responses'] !=
'' ) {
394 foreach ($res[
'responses'] as &$response) {
395 if (strlen($response[
'body']) > 50) {
396 $response[
'body'] = substr($response[
'body'], 0, 50) .
'...';
425 $prefix = str_replace(
':',
'_', $prefix);
429 if (!isset($_REQUEST[$prefix.
'_method']))
return FALSE;
432 $value[
'method'] = (isset($_REQUEST[$prefix.
'_method'])) ? $_REQUEST[$prefix.
'_method'] :
'';
436 $value[
'urls'] = trim($ol->value) ? explode($ol->delimiter, $ol->value) : NULL;
438 $value[
'timeout'] = (isset($_REQUEST[$prefix.
'_timeout'])) ? $_REQUEST[$prefix.
'_timeout'] : 0;
439 $value[
'follow_redirect'] = (isset($_REQUEST[$prefix.
'_follow_redirect'])) ? $_REQUEST[$prefix.
'_follow_redirect'] : FALSE;
440 $value[
'disable_ssl_verify'] = (isset($_REQUEST[$prefix.
'_disable_ssl_verify'])) ? $_REQUEST[$prefix.
'_disable_ssl_verify'] : FALSE;
441 $value[
'cache_options'] = (isset($_REQUEST[$prefix.
'_cache_options'])) ? $_REQUEST[$prefix.
'_cache_options'] :
'HTTP';
442 $value[
'cache_post_requests'] = (isset($_REQUEST[$prefix.
'_cache_post_requests'])) ? $_REQUEST[$prefix.
'_cache_post_requests'] : FALSE;
443 $value[
'default_cache_expiry'] = (isset($_REQUEST[$prefix.
'_default_cache_expiry'])) ? $_REQUEST[$prefix.
'_default_cache_expiry'] : 60;
444 $value[
'authentication_type'] = (isset($_REQUEST[$prefix.
'_authentication_type'])) ? $_REQUEST[$prefix.
'_authentication_type'] :
'';
445 $value[
'request_body'] = (isset($_REQUEST[$prefix.
'_request_body'])) ? trim($_REQUEST[$prefix.
'_request_body']) :
'';
448 $hl->process($prefix.
'_request_headers');
449 $value[
'request_headers'] = trim($hl->value) ? explode($hl->delimiter, $hl->value) : NULL;
451 $value[
'convert_to_utf8'] = (isset($_REQUEST[$prefix.
'_convert_to_utf8'])) ? $_REQUEST[$prefix.
'_convert_to_utf8'] : FALSE;
452 $value[
'append_get_vars'] = (isset($_REQUEST[$prefix.
'_append_get_vars'])) ? $_REQUEST[$prefix.
'_append_get_vars'] : FALSE;
453 $value[
'forward_user_keys'] = (isset($_REQUEST[$prefix.
'_forward_user_keys'])) ? $_REQUEST[$prefix.
'_forward_user_keys'] : FALSE;
454 $value[
'document_encoding'] = (isset($_REQUEST[$prefix.
'_document_encoding'])) ? $_REQUEST[$prefix.
'_document_encoding'] :
'Auto';
455 $value[
'run_test'] = (isset($_REQUEST[$prefix.
'_run_test'])) ? trim($_REQUEST[$prefix.
'_run_test']) : FALSE;
456 $value[
'http_auth_options'][
'username'] = (isset($_REQUEST[$prefix.
'_http_auth_user'])) ? $_REQUEST[$prefix.
'_http_auth_user'] :
'';
457 $value[
'http_auth_options'][
'password'] = (isset($_REQUEST[$prefix.
'_http_auth_pass'])) ? $_REQUEST[$prefix.
'_http_auth_pass'] :
'';
459 $value[
'oauth_asset'] = (isset($_REQUEST[$prefix.
'_oauth_asset'])) ? $_REQUEST[$prefix.
'_oauth_asset'] :
'';
461 $this->processed = $this->setValue($value);
476 $this->_keyword_replacements = $replacements;
489 $this->_config = @unserialize($this->value);
490 if (empty($this->_config))
return;
491 if ($this->_config[
'authentication_type'] ==
'OAuth' && $this->_config[
'oauth_asset'][
'assetid'] == 0)
return;
496 'method' => $this->_config[
'method'],
497 'headers' => count($this->_config[
'request_headers']) ? $this->_config[
'request_headers'] : Array(),
498 'body' => $this->_config[
'request_body'],
499 'urls' => count($this->_config[
'urls']) ? $this->_config[
'urls'] : Array(),
501 'type' => $this->_config[
'authentication_type'],
504 'responses' => Array(),
505 'response' => Array(),
509 if (count($this->_res[
'request'][
'urls']) < 1)
return $this->_res;
512 foreach ($this->_res[
'request'][
'urls'] as &$url) {
516 if ($this->_config[
'append_get_vars']) {
517 $query_vars = $collection_var =
'';
518 foreach ($_GET as $query => $param) {
519 $param = str_replace(
' ',
'+', $param);
520 if ($query ==
'collection') {
521 $collection_var .= $query.
'='.$param;
524 $prefix = empty($query_vars) ?
'' :
'&';
525 $query_vars .= $prefix.$query.
'='.$param;
528 if(!empty($query_vars) || !empty($collection_var)) {
529 foreach ($this->_res[
'request'][
'urls'] as $index => $url) {
530 if (strpos($url,
'?') === FALSE) $url .=
'?';
531 if (strpos($url,
'collection=') === FALSE) $url .= $collection_var;
532 $prefix = empty($collection_var) ?
'' :
'&';
533 $this->_res[
'request'][
'urls'][$index] = $url.$prefix.$query_vars;
540 if ($this->_config[
'forward_user_keys']) {
541 $user_info = Array($GLOBALS[
'SQ_SYSTEM']->user->id);
542 $user_info = array_merge($GLOBALS[
'SQ_SYSTEM']->user->getUserGroups(), $user_info);
543 $user_keys =
'userkeys='.implode(
',', $user_info);
544 foreach ($this->_res[
'request'][
'urls'] as $index => $url) {
545 $url .= (strpos($url,
'?') === FALSE) ?
'?' :
'&';
546 $this->_res[
'request'][
'urls'][$index] = $url.$user_keys;
549 $this->_res[
'request'][
'headers'][] =
'X-Forwarded-For: '.$_SERVER[
'REMOTE_ADDR'];
553 for ($i = 0; $i < count($this->_res[
'request'][
'headers']); $i++) {
557 if (preg_match(
'/(.+):(.+)/', $this->_res[
'request'][
'headers'][$i]) == 0) {
558 unset($this->_res[
'request'][
'headers'][$i]);
566 switch ($this->_res[
'request'][
'auth'][
'type']) {
568 $this->_res[
'request'][
'auth'][
'http_auth_options'] = $this->_config[
'http_auth_options'];
569 $this->
_replaceKeywords($this->_res[
'request'][
'auth'][
'http_auth_options'][
'username']);
570 $this->
_replaceKeywords($this->_res[
'request'][
'auth'][
'http_auth_options'][
'password']);
575 $oauth_asset = $GLOBALS[
'SQ_SYSTEM']->am->getAsset($this->_config[
'oauth_asset'][
'assetid'],
'', TRUE);
576 if (!is_null($oauth_asset)) {
578 $args[
'method'] = $this->_res[
'request'][
'method'];
579 $args[
'request_headers'] = $this->_res[
'request'][
'headers'];
580 $args[
'request_body'] =$this->_res[
'request'][
'body'];
581 $this->_res[
'request'][
'oauth_headers'] = $oauth_asset->getUserDataRequestAuthHeaders($this->_res[
'request'][
'urls'], $args);
591 if (isset($this->_config[
'convert_to_utf8']) && ($this->_config[
'convert_to_utf8'])) {
592 $doc_encoding = $this->_config[
'document_encoding'];
596 if ($doc_encoding !=
'UTF-8') {
597 foreach ($this->_res[
'responses'] as $index => $response) {
600 if ($doc_encoding ==
'Auto') {
606 if (strlen($doc_encoding) > 0 && array_get_index($this->_document_encoding, $doc_encoding) && $doc_encoding !=
'UTF-8') {
607 $this->_res[
'responses'][$index][
'body'] = iconv($doc_encoding,
'UTF-8', $response[
'body']);
614 $this->_res[
'request'][
'url'] = &$this->_res[
'request'][
'urls'][0];
617 $this->_res[
'response'] =& $this->_res[
'responses'][0];
636 $content_type_info = explode(
';', $response[
'info'][
'content_type']);
637 if (isset($content_type_info[0])) {
638 $content_type = $content_type_info[0];
641 if (strcasecmp($content_type,
'text/html') == 0) {
643 if (isset($content_type_info[1]) && substr(trim($content_type_info[1]), 0, strlen(
'charset=')) ==
'charset=') {
644 $charset = substr(trim($content_type_info[1]), strlen(
'charset='));
647 preg_match_all(
"|<meta http-equiv=[^>]+content=[\"\']text/html;[\s]?charset=[^>]+/>|U", $response[
'body'], $matches);
648 if (isset($matches[0][0])) {
649 $charset = preg_replace(
"/.*charset=/i",
"", $matches[0][0]);
650 $charset = trim(str_replace(Array(
"/",
">",
"\""),
"", $charset));
655 return strtoupper($charset);
670 replace_keywords($text, $this->_keyword_replacements);
671 replace_global_keywords($text);
686 $cm = $GLOBALS[
'SQ_SYSTEM']->am->getSystemAsset(
'cache_manager');
687 $rm = $GLOBALS[
'SQ_SYSTEM']->am->getSystemAsset(
'rest_manager');
693 for ($key = 0; $key < count($this->_res[
'request'][
'urls']); $key++) {
694 $url = $this->_res[
'request'][
'urls'][$key];
697 $current_request = $this->_res[
'request'];
698 $current_request[
'urls'] = NULL;
699 $current_request[
'current_url'] = $url;
700 $cache_key = serialize($current_request);
705 $cache =& $cm->loadFromCache($rm->id,
'rest_manager', $cache_key, FALSE);
707 if ($cache !== FALSE) {
709 $this->_res[
'responses'][$key] = unserialize($cache);
710 $this->_res[
'responses'][$key][
'source'] =
'cache';
713 $this->_res[
'responses'][$key] = Array();
719 for ($key = 0; $key < count($this->_res[
'request'][
'urls']); $key++) {
720 $this->_res[
'responses'][$key] = Array();
721 $this->
_curlAddUrl($this->_res[
'request'][
'urls'][$key], $key);
739 switch ($this->_config[
'cache_options']) {
744 switch ($this->_res[
'request'][
'method']) {
748 return $this->_config[
'cache_post_requests'];
768 if (isset($this->_res[
'request'][
'oauth_headers'])) {
769 if (isset($this->_res[
'request'][
'oauth_headers'][$url])) {
770 $this->_res[
'request'][
'headers'][] = $this->_res[
'request'][
'oauth_headers'][$url];
774 curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
775 curl_setopt($ch, CURLOPT_URL, $url);
776 curl_setopt($ch, CURLOPT_FOLLOWLOCATION, $this->_config[
'follow_redirect']);
777 curl_setopt($ch, CURLOPT_TIMEOUT, $this->_config[
'timeout']);
778 curl_setopt($ch, CURLOPT_HEADERFUNCTION, Array($this,
'_readCurlHeaders'));
779 curl_setopt($ch, CURLOPT_HTTPHEADER, $this->_res[
'request'][
'headers']);
783 $proxy = get_proxy_info_for_url($url);
784 if (!empty($proxy[
'host'])) {
785 curl_setopt($ch, CURLOPT_PROXY, $proxy[
'host']);
786 curl_setopt($ch, CURLOPT_PROXYPORT, $proxy[
'port']);
787 if (!empty($proxy[
'user'])) {
788 curl_setopt($ch, CURLOPT_PROXYUSERPWD, $proxy[
'user'] .
':' . $proxy[
'password']);
793 if (isset($this->_config[
'disable_ssl_verify']) && $this->_config[
'disable_ssl_verify']) {
794 curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
795 curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
799 switch ($this->_res[
'request'][
'method']) {
801 curl_setopt($ch, CURLOPT_HTTPGET, 1);
804 curl_setopt($ch, CURLOPT_HTTPGET, 1);
805 curl_setopt($ch, CURLOPT_NOBODY, 1);
808 curl_setopt($ch, CURLOPT_POST, 1);
809 curl_setopt($ch, CURLOPT_POSTFIELDS, $this->_res[
'request'][
'body']);
812 curl_setopt($ch, CURLOPT_CUSTOMREQUEST,
'PUT');
813 curl_setopt($ch, CURLOPT_POSTFIELDS, $this->_res[
'request'][
'body']);
816 curl_setopt($ch, CURLOPT_CUSTOMREQUEST,
'DELETE');
821 switch ($this->_res[
'request'][
'auth'][
'type']) {
823 curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
824 curl_setopt($ch, CURLOPT_USERPWD, $this->_res[
'request'][
'auth'][
'http_auth_options'][
'username'].
':'.$this->_res[
'request'][
'auth'][
'http_auth_options'][
'password']);
827 curl_setopt($ch, CURLOPT_COOKIE,
'SQ_SYSTEM_SESSION=' . $_COOKIE[
'SQ_SYSTEM_SESSION']);
828 curl_setopt($ch,CURLOPT_COOKIESESSION,
true);
829 session_write_close();
833 $this->_urls_to_request[$key] = Array(
'handle' => $ch,
'url' => $url);
846 for ($key = 0; $key < count($this->_res[
'request'][
'urls']); $key++) {
849 if (!isset($this->_urls_to_request[$key][
'url']))
continue;
851 $response =& $this->_res[
'responses'][$key];
854 $response[
'body'] = curl_exec($this->_urls_to_request[$key][
'handle']);
855 $response[
'headers'] = $this->_headers;
856 $response[
'info'] = curl_getinfo($this->_urls_to_request[$key][
'handle']);
857 $response[
'source'] =
'remote';
860 if ($response[
'body'] === FALSE) {
861 trigger_error(
"cURL request failed: '" . $this->_urls_to_request[$key][
'url'] .
"': " . curl_error($this->_urls_to_request[$key][
'handle']), E_USER_WARNING);
865 curl_close($this->_urls_to_request[$key][
'handle']);
866 $this->_headers = Array();
869 if ($this->_res[
'request'][
'auth'][
'type'] ===
'Matrix')
877 if ($response[
'expiry'] > 0) {
880 $current_request = $this->_res[
'request'];
881 $current_request[
'urls'] = NULL;
882 $current_request[
'current_url'] = $this->_urls_to_request[$key][
'url'];
883 $cache_key = serialize($current_request);
886 $cm = $GLOBALS[
'SQ_SYSTEM']->am->getSystemAsset(
'cache_manager');
887 $rm = $GLOBALS[
'SQ_SYSTEM']->am->getSystemAsset(
'rest_manager');
888 $cm->saveToCache($rm->id,
'rest_manager', $cache_key, serialize($response), FALSE, $response[
'expiry']);
894 $this->_urls_to_request = Array();
912 switch ($this->_config[
'cache_options']) {
917 $cache_control = isset($response[
'headers'][
'Cache-Control']) ? $response[
'headers'][
'Cache-Control'] : NULL;
918 $pragma = isset($response[
'headers'][
'Pragma']) ? $response[
'headers'][
'Pragma'] : NULL;
919 $expires = isset($response[
'headers'][
'Expires']) ? $response[
'headers'][
'Expires'] : NULL;
922 if ((!is_null($cache_control)) || (!is_null($pragma))) {
925 if ($pragma ==
'no-cache') {
926 $response[
'expiry'] = 0;
930 $cache_directives = explode(
',', $cache_control);
931 foreach ($cache_directives as $directive) {
934 $cache_ext = explode(
'=', $directive);
938 switch (strtolower(trim($cache_ext[0]))) {
940 case 'must-revalidate':
943 $response[
'expiry'] = 0;
947 $response[
'expiry'] = isset($cache_ext[1]) ? (int) $cache_ext[1] : NULL;
950 $response[
'expiry'] = isset($cache_ext[1]) ? (int) $cache_ext[1] : NULL;
955 } elseif (!is_null($expires)) {
957 $time = (strtotime($expires) - time());
958 if ($time < 0) $time = 0;
959 $response[
'expiry'] = $time;
962 if (empty($response[
'expiry'])) {
963 $response[
'expiry'] = 0;
969 $response[
'expiry'] = $this->_config[
'default_cache_expiry'];
972 $response[
'expiry'] = (int) $response[
'expiry'];
985 if ($this->_last_header) {
986 $this->_headers = Array();
987 $this->_last_header = FALSE;
991 if (trim($header) ==
'') {
992 $this->_last_header = TRUE;
994 $pair = explode(
': ', $header);
995 if (count($pair) == 2) {
996 $this->_headers[trim($pair[0])] = trim($pair[1]);
1001 return strlen($header);