Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions Tests/HttpFactoryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion docs/classes/Http.md
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 2 additions & 0 deletions docs/classes/HttpFactory.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
/**
Expand Down
11 changes: 3 additions & 8 deletions src/HttpFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -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)));
}
}
Loading