CRM-13967 allow additional of anonymous tokens for logged out users when viewing...
[civicrm-core.git] / CRM / Utils / HttpClient.php
index 6aaa9d026e9de6339a40b67748e26e22bc747533..14bf423f7480f269640a134259899257d8db47bc 100644 (file)
@@ -1,7 +1,7 @@
 <?php
 /*
  +--------------------------------------------------------------------+
- | CiviCRM version 4.3                                                |
+ | CiviCRM version 4.4                                                |
  +--------------------------------------------------------------------+
  | Copyright CiviCRM LLC (c) 2004-2013                                |
  +--------------------------------------------------------------------+
@@ -50,9 +50,9 @@ class CRM_Utils_HttpClient {
   protected static $singleton;
 
   /**
-   * @var int
+   * @var int|NULL seconds; or NULL to use system default
    */
-  protected $timeout;
+  protected $connectionTimeout;
 
   public static function singleton() {
     if (!self::$singleton) {
@@ -61,8 +61,8 @@ class CRM_Utils_HttpClient {
     return self::$singleton;
   }
 
-  public function __construct($timeout = 10) {
-    $this->timeout = $timeout;
+  public function __construct($connectionTimeout = NULL) {
+    $this->connectionTimeout = $connectionTimeout;
   }
 
   /**
@@ -129,7 +129,7 @@ class CRM_Utils_HttpClient {
     curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
     $data = curl_exec($ch);
     if (curl_errno($ch)) {
-      return array(self::STATUS_DL_ERROR . $data);
+      return array(self::STATUS_DL_ERROR, $data);
     }
     else {
       curl_close($ch);
@@ -165,7 +165,7 @@ class CRM_Utils_HttpClient {
     curl_setopt($ch, CURLOPT_POSTFIELDS,$params);
     $data = curl_exec($ch);
     if (curl_errno($ch)) {
-      return array(self::STATUS_DL_ERROR . $data);
+      return array(self::STATUS_DL_ERROR, $data);
     }
     else {
       curl_close($ch);
@@ -190,6 +190,9 @@ class CRM_Utils_HttpClient {
     curl_setopt($ch, CURLOPT_ENCODING, 'gzip');
     curl_setopt($ch, CURLOPT_VERBOSE, 0);
     curl_setopt($ch, CURLOPT_FOLLOWLOCATION, TRUE);
+    if ($this->connectionTimeout !== NULL) {
+      curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $this->connectionTimeout);
+    }
     if (preg_match('/^https:/', $remoteFile) && $caConfig->isEnableSSL()) {
       curl_setopt_array($ch, $caConfig->toCurlOptions());
     }