debug) { $cache = new CRM_Utils_Cache_Arraycache(array()); } else { $cache = new CRM_Utils_Cache_SqlGroup(array( 'group' => 'CiviCxnHttp', 'prefetch' => FALSE, )); } self::$singleton = new CRM_Cxn_CiviCxnHttp($cache); } return self::$singleton; } /** * @param CRM_Utils_Cache_Interface|NULL $cache * The cache data store. */ public function __construct($cache) { $this->cache = $cache; } /** * @param string $verb * @param string $url * @param string $blob * @param array $headers * Array of headers (e.g. "Content-type" => "text/plain"). * @return array * array($headers, $blob, $code) */ public function send($verb, $url, $blob, $headers = array()) { $lowVerb = strtolower($verb); if ($lowVerb === 'get' && $this->cache) { $cachePath = 'get/' . md5($url); $cacheLine = $this->cache->get($cachePath); if ($cacheLine && $cacheLine['expires'] > CRM_Utils_Time::getTimeRaw()) { return $cacheLine['data']; } } $result = parent::send($verb, $url, $blob, $headers); if ($lowVerb === 'get' && $this->cache) { $expires = CRM_Utils_Http::parseExpiration($result[0]); if ($expires !== NULL) { $cachePath = 'get/' . md5($url); $cacheLine = array( 'url' => $url, 'expires' => $expires, 'data' => $result, ); $this->cache->set($cachePath, $cacheLine); } } return $result; } protected function createStreamOpts($verb, $url, $blob, $headers) { $result = parent::createStreamOpts($verb, $url, $blob, $headers); $caConfig = CA_Config_Stream::probe(array( 'verify_peer' => (bool) CRM_Core_BAO_Setting::getItem(CRM_Core_BAO_Setting::SYSTEM_PREFERENCES_NAME, 'verifySSL', NULL, TRUE), )); if ($caConfig->isEnableSSL()) { $result['ssl'] = $caConfig->toStreamOptions(); } if (!$caConfig->isEnableSSL() && preg_match('/^https:/', $url)) { CRM_Core_Error::fatal('Cannot fetch document - system does not support SSL'); } return $result; } }