]> git.mxchange.org Git - quix0rs-gnu-social.git/blobdiff - lib/httpclient.php
Misses this file to merge. I like the comments.
[quix0rs-gnu-social.git] / lib / httpclient.php
index a92c7d8c5be96d70cc8cbf14cd6bcd9e9b3032fc..6016f89314400e90059a1b93eaf232a9a482219c 100644 (file)
@@ -145,6 +145,10 @@ class HTTPClient extends HTTP_Request2
             $this->config['ssl_verify_peer'] = false;
         }
 
+        // This means "verify the cert hostname against what we connect to", it does not
+        // imply CA trust or anything like that. Just the hostname.
+        $this->config['ssl_verify_host'] = common_config('http', 'ssl_verify_host');
+
         if (common_config('http', 'curl') && extension_loaded('curl')) {
             $this->config['adapter'] = 'HTTP_Request2_Adapter_Curl';
         }
@@ -158,7 +162,7 @@ class HTTPClient extends HTTP_Request2
         }
 
         parent::__construct($url, $method, $config);
-        $this->setHeader('User-Agent', $this->userAgent());
+        $this->setHeader('User-Agent', self::userAgent());
     }
 
     /**
@@ -170,6 +174,23 @@ class HTTPClient extends HTTP_Request2
         return new HTTPClient();
     }
 
+    /**
+     * Quick static function to GET a URL
+     */
+    public static function quickGet($url, $accept=null)
+    {
+        $client = new HTTPClient();
+        if (!is_null($accept)) {
+            $client->setHeader('Accept', $accept);
+        }
+        $response = $client->get($url);
+        if (!$response->isOk()) {
+            // TRANS: Exception. %s is a profile URL.
+            throw new Exception(sprintf(_m('Could not GET URL %s.'), $url), $response->getStatus());
+        }
+        return $response->getBody();
+    }
+
     /**
      * Convenience function to run a GET request.
      *
@@ -247,9 +268,10 @@ class HTTPClient extends HTTP_Request2
      *
      * @return string
      */
-    function userAgent()
+    static public function userAgent()
     {
-        return "GNU Social/".STATUSNET_VERSION." (".STATUSNET_CODENAME.")";
+        return GNUSOCIAL_ENGINE . '/' . GNUSOCIAL_VERSION
+                . ' (' . GNUSOCIAL_CODENAME . ')';
     }
 
     /**