Add new tests for curl/http-1.0 and socket/https
authorgggeek <giunta.gaetano@gmail.com>
Sun, 5 Nov 2017 23:25:43 +0000 (23:25 +0000)
committergggeek <giunta.gaetano@gmail.com>
Sun, 5 Nov 2017 23:25:43 +0000 (23:25 +0000)
NEWS
src/Client.php
tests/4LocalhostMultiTest.php

diff --git a/NEWS b/NEWS
index b5d4218..2d2f6c7 100644 (file)
--- a/NEWS
+++ b/NEWS
@@ -1,9 +1,11 @@
-XML-RPC for PHP version 4.2.3 - 2017/11/5
+XML-RPC for PHP version 4.3.0 - 2017/11/5
 
 * fixed: compatibility with Basic/Digest/NTLM auth when using client in cURL mode (issue #55)
 
 * improved: added unit tests for Basic and Digest http auth. Also improved unit tests for feature of the http protocol
 
+* new: allow to force usage of curl for http &.0 calls, as well as plain socket for https calls, via the method
+    `Client::setUseCurl()`
 
 XML-RPC for PHP version 4.2.2 - 2017/10/15
 
index 4698478..c327bbb 100644 (file)
@@ -9,6 +9,10 @@ use PhpXmlRpc\Helper\Logger;
  */
 class Client
 {
+    const USE_CURL_NEVER = 0;
+    const USE_CURL_ALWAYS = 1;
+    const USE_CURL_AUTO = 2;
+
     /// @todo: do these need to be public?
     public $method = 'http';
     public $server;
@@ -41,6 +45,7 @@ class Client
 
     public $cookies = array();
     public $extracurlopts = array();
+    public $use_curl = self::USE_CURL_AUTO;
 
     /**
      * @var bool
@@ -69,6 +74,7 @@ class Client
      */
 
     public $request_compression = '';
+
     /**
      * CURL handle: used for keep-alive connections (PHP 4.3.8 up, see:
      * http://curl.haxx.se/docs/faq.html#7.3).
@@ -177,7 +183,7 @@ class Client
         $this->accepted_charset_encodings = array('UTF-8', 'ISO-8859-1', 'US-ASCII');
 
         // Add all charsets which mbstring can handle, but remove junk not found in IANA registry at
-        // in http://www.iana.org/assignments/character-sets/character-sets.xhtml
+        // http://www.iana.org/assignments/character-sets/character-sets.xhtml
         // NB: this is disabled to avoid making all the requests sent huge... mbstring supports more than 80 charsets!
         /*if (function_exists('mb_list_encodings')) {
 
@@ -201,7 +207,7 @@ class Client
      * This option can be very useful when debugging servers as it allows you to see exactly what the client sends and
      * the server returns.
      *
-     * @param integer $in values 0, 1 and 2 are supported (2 = echo sent msg too, before received response)
+     * @param integer $level values 0, 1 and 2 are supported (2 = echo sent msg too, before received response)
      */
     public function setDebug($level)
     {
@@ -413,6 +419,15 @@ class Client
         $this->extracurlopts = $options;
     }
 
+    /**
+     * @param int $useCurlMode self::USE_CURL_ALWAYS, self::USE_CURL_AUTO or self::USE_CURL_NEVER
+     */
+    public function setUseCurl($useCurlMode)
+    {
+        $this->use_curl = $useCurlMode;
+    }
+
+
     /**
      * Set user-agent string that will be used by this client instance in http headers sent to the server.
      *
@@ -473,8 +488,9 @@ class Client
         $req->setDebug($this->debug);
 
         /// @todo we could be smarter about this and force usage of curl in scenarios where it is both available and
-        ///       needed, such as digest or ntlm auth
-        $useCurl = ($method == 'https' || $method == 'http11');
+        ///       needed, such as digest or ntlm auth. Do not attempt to use it for https if not present
+        $useCurl = ($this->use_curl == self::USE_CURL_ALWAYS) || ($this->use_curl == self::USE_CURL_AUTO &&
+            ($method == 'https' || $method == 'http11'));
 
         if ($useCurl) {
             $r = $this->sendPayloadCURL(
index f4c5b17..0516c30 100644 (file)
@@ -22,7 +22,7 @@ class LocalhostMultiTest extends LocalhostTest
     public function getSingleHttpTestMethods()
     {
         $unsafeMethods = array(
-            'testHttps', 'testCatchExceptions', 'testUtf8Method', 'testServerComments',
+            'testCatchExceptions', 'testUtf8Method', 'testServerComments',
             'testExoticCharsetsRequests', 'testExoticCharsetsRequests2', 'testExoticCharsetsRequests3',
         );
 
@@ -131,6 +131,26 @@ class LocalhostMultiTest extends LocalhostTest
         $this->$method();
     }
 
+    /**
+     * @dataProvider getSingleHttpTestMethods
+     * @param string $method
+     */
+    public function testHttp10Curl($method)
+    {
+        if(!function_exists('curl_init'))
+        {
+            $this->markTestSkipped('CURL missing: cannot test http 1.1');
+            return;
+        }
+
+        $this->method = 'http10'; // not an error the double assignment!
+        $this->client->method = 'http10';
+        $this->client->keepalive = false;
+        $this->client->setUseCurl(\PhpXmlRpc\Client::USE_CURL_ALWAYS);
+
+        $this->$method();
+    }
+
     /**
      * @dataProvider getSingleHttpTestMethods
      * @param string $method
@@ -224,6 +244,30 @@ class LocalhostMultiTest extends LocalhostTest
         $this->$method();
     }
 
+    /**
+     * @dataProvider getSingleHttpTestMethods
+     * @param string $method
+     */
+    public function testHttpsSocket($method)
+    {
+        if ($this->args['HTTPSSERVER'] == '')
+        {
+            $this->markTestSkipped('HTTPS SERVER definition missing: cannot test https');
+            return;
+        }
+
+        $this->client->server = $this->args['HTTPSSERVER'];
+        $this->method = 'https';
+        $this->client->method = 'https';
+        $this->client->path = $this->args['HTTPSURI'];
+        $this->client->setSSLVerifyPeer(!$this->args['HTTPSIGNOREPEER']);
+        $this->client->setSSLVerifyHost($this->args['HTTPSVERIFYHOST']);
+        $this->client->setSSLVersion($this->args['SSLVERSION']);
+        $this->client->setUseCurl(\PhpXmlRpc\Client::USE_CURL_NEVER);
+
+        $this->$method();
+    }
+
     /**
      * @dataProvider getSingleHttpTestMethods
      * @param string $method