be smarter about when to trigger auto usage of curl
authorgggeek <giunta.gaetano@gmail.com>
Wed, 8 Feb 2023 16:27:52 +0000 (16:27 +0000)
committergggeek <giunta.gaetano@gmail.com>
Wed, 8 Feb 2023 16:27:52 +0000 (16:27 +0000)
NEWS.md
src/Client.php

diff --git a/NEWS.md b/NEWS.md
index 5214c3f..ac983e0 100644 (file)
--- a/NEWS.md
+++ b/NEWS.md
 
 * new: method `PhpXmlRpc::setLogger()`, to simplify injecting a custom logger into all classes of the library in one step
 
+* improved: the Client will automatically try to use cURL for requests using Digest/NTLM auth, unless told explicitly
+  told not to do so via option 'use_curl'
+
 * improved: the Client is more verbose in logging issues when trying to compress a Request for sending
 
 * improved: the `Logger` class now sports methods adhering to Psr\Log\LoggerInterface
index 6292d55..7850dd9 100644 (file)
@@ -829,10 +829,13 @@ class Client
         // where req is a Request
         $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. 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 &&
-                (in_array($method, array('https', 'http11', 'h2c', 'h2'))));
+        /// @todo we could be smarter about this and not force usage of curl for https if not present, as well as
+        ///       use the presence of curl_extra_opts or socket_extra_opts as a hint
+        $useCurl = ($this->use_curl == self::USE_CURL_ALWAYS) || ($this->use_curl == self::USE_CURL_AUTO && (
+            in_array($method, array('https', 'http11', 'h2c', 'h2')) ||
+            ($this->username != '' && $this->authtype != 1) ||
+            ($this->proxy != '' && $this->proxy_user != '' && $this->proxy_authtype != 1)
+        ));
 
         // BC - we go through sendPayloadCURL/sendPayloadSocket in case some subclass reimplemented those
         if ($useCurl) {