From fd510519b504a0b95869687e240f1c23adde691a Mon Sep 17 00:00:00 2001 From: Hannes Papenberg Date: Fri, 13 Nov 2026 00:12:05 +0100 Subject: [PATCH] Prefer the stream transport over the socket transport The transports were sorted alphabetically with only cURL moved to the front, so without ext-curl the factory picked the socket transport before the stream transport. The socket transport is the weakest of the three: it cannot be configured for TLS, does not support proxies and does not decode chunked responses. Order the transports explicitly as cURL, stream, socket. Co-Authored-By: Claude Opus 5.5 --- Tests/HttpFactoryTest.php | 4 ++-- docs/classes/Http.md | 2 +- docs/classes/HttpFactory.md | 2 ++ src/HttpFactory.php | 11 +++-------- 4 files changed, 8 insertions(+), 11 deletions(-) diff --git a/Tests/HttpFactoryTest.php b/Tests/HttpFactoryTest.php index 76b4fda6..8e55f94b 100644 --- a/Tests/HttpFactoryTest.php +++ b/Tests/HttpFactoryTest.php @@ -130,8 +130,8 @@ public function testGetAvailableDriverDisallowsNonArrayObjects() */ public function testGetHttpTransports() { - $transports = ['Stream', 'Socket', 'Curl']; - sort($transports); + // cURL first, the socket transport only as the last resort + $transports = ['Curl', 'Stream', 'Socket']; $this->assertEquals( $transports, diff --git a/docs/classes/Http.md b/docs/classes/Http.md index 80777e03..cb182d45 100644 --- a/docs/classes/Http.md +++ b/docs/classes/Http.md @@ -8,7 +8,7 @@ for making requests as well. Construction of `Http` object is generally done using the [Joomla\Http\HttpFactory](HttpFactory.md) class. However, `Http` is not abstract and can be instantiated directly passing an optional array of options and an optional [Joomla\Http\TransportInterface](TransportInterface.md) object. If the transport is omitted, the default transport will be used. The default is determined by looking up the transports folder and selecting -the first transport that is supported; this will usually be the "curl" transport. +the first transport that is supported, in the order cURL, stream, socket; this will usually be the "curl" transport. ```php use Joomla\Http\Http; diff --git a/docs/classes/HttpFactory.md b/docs/classes/HttpFactory.md index 1003805e..e4d308fb 100644 --- a/docs/classes/HttpFactory.md +++ b/docs/classes/HttpFactory.md @@ -64,6 +64,8 @@ interface. ### Retrieving the available TransportInterface implementations The `getHttpTransports()` method can be used to retrieve a list of supported [TransportInterface](TransportInterface.md) objects from the factory. +The list is in order of preference: `Curl`, `Stream`, then `Socket` (and any other transport found in the folder after +them), which is also the order in which `getHttp()` and `getAvailableDriver()` try them when no adapter is given. ```php /** diff --git a/src/HttpFactory.php b/src/HttpFactory.php index b5ccb726..f7e2d95f 100644 --- a/src/HttpFactory.php +++ b/src/HttpFactory.php @@ -117,14 +117,9 @@ public function getHttpTransports() // Keep alphabetical order across all environments sort($names); - // If curl is available set it to the first position - $key = array_search('Curl', $names); + // Prefer cURL, then streams; the socket transport is the weakest and only used as the last resort + $preferred = array_values(array_intersect(['Curl', 'Stream', 'Socket'], $names)); - if ($key) { - unset($names[$key]); - array_unshift($names, 'Curl'); - } - - return $names; + return array_merge($preferred, array_values(array_diff($names, $preferred))); } }