add one more Client option
authorgggeek <giunta.gaetano@gmail.com>
Wed, 8 Feb 2023 16:03:30 +0000 (16:03 +0000)
committergggeek <giunta.gaetano@gmail.com>
Wed, 8 Feb 2023 16:03:30 +0000 (16:03 +0000)
NEWS.md
src/Client.php
tests/09HTTPTest.php

diff --git a/NEWS.md b/NEWS.md
index 6a8f707..5214c3f 100644 (file)
--- a/NEWS.md
+++ b/NEWS.md
 * new: added methods `getOption`, `setOption`, `setOptions` and `getOptions` to both Client and Server, meant to replace
   direct access to _all public properties_ as well as the `$timeout` argument in calls to `Client::send` and `Client::multicall`
 
+* new: by using `Client::setOption('extracurlopts')`, it is possible to pass in protocol=specific options for when
+  using the Socket http transport. The value has to be an array with key being 'socket' or 'ssl', and the value an array
+  (see https://www.php.net/manual/en/context.socket.php and https://www.php.net/manual/en/context.ssl.php)
+
 * new: it is now possible to inject a custom logger into helper classes `Charset`, `Http`, `XMLParser`, inching a step
   closer to supporting DIC patterns (issue #78)
 
index f45c6a2..3a6662b 100644 (file)
@@ -36,6 +36,7 @@ class Client
     const OPT_COOKIES = 'cookies';
     const OPT_DEBUG = 'debug';
     const OPT_EXTRA_CURL_OPTS = 'extracurlopts';
+    const OPT_EXTRA_SOCKET_OPTS = 'extrasockopts';
     const OPT_KEEPALIVE = 'keepalive';
     const OPT_KEY = 'key';
     const OPT_KEY_PASS = 'keypass';
@@ -168,6 +169,10 @@ class Client
      * @var array
      */
     protected $cookies = array();
+    /**
+     * @var array
+     */
+    protected $extrasockopts = array();
     /**
      * @var array
      */
@@ -1032,6 +1037,12 @@ class Client
             $contextOptions['ssl']['verify_peer_name'] = $opts['verifypeer'];
         }
 
+        foreach ($opts['extracurlopts'] as $proto => $protoOpts) {
+            foreach ($protoOpts as $key => $val) {
+                $contextOptions[$proto][$key] = $val;
+            }
+        }
+
         $context = stream_context_create($contextOptions);
 
         if ($opts['timeout'] <= 0) {
index ed4348e..ffff037 100644 (file)
@@ -332,6 +332,13 @@ class HTTPTest extends ServerTest
         $this->client->setSSLVersion($this->args['SSLVERSION']);
         $this->client->setUseCurl(\PhpXmlRpc\Client::USE_CURL_NEVER);
 
+        if (version_compare(PHP_VERSION, '8.0', '>'))
+        {
+            $version = explode('.', PHP_VERSION);
+            $this->client->setOption(\PhpXmlRpc\Client::OPT_EXTRA_SOCKET_OPTS,
+                array('ssl' => array('security_level' => 2 + $version[1])));
+        }
+
         $this->$method();
     }