Skip to content
Open
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
33 changes: 31 additions & 2 deletions src/Transport/Curl.php
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,15 @@
$options[\CURLOPT_HTTP_VERSION] = $this->mapProtocolVersion($protocolVersion);
}

// Proxy configuration
if ($this->getOption('proxy.enabled', false)) {
$options[CURLOPT_PROXY] = $this->getOption('proxy.host') . ':' . $this->getOption('proxy.port');

if ($user = $this->getOption('proxy.user')) {
$options[CURLOPT_PROXYUSERPWD] = $user . ':' . $this->getOption('proxy.pass');
}
}

// Set any custom transport options
foreach ($this->getOption('transport.curl', []) as $key => $value) {
$options[$key] = $value;
Expand Down Expand Up @@ -184,7 +193,20 @@
// Close the connection.
curl_close($ch);

return $this->getResponse($content, $info);
$response = $this->getResponse($content, $info);

// Manually follow redirects if server doesn't allow to follow location using curl
if ($response->getStatusCode() >= 301 && $response->getStatusCode() < 400 && isset($response->getHeaders()['Location']) && (bool) $this->getOption('follow_location', true)) {
$redirect_uri = $response->getHeaders()['Location'][0];

if (str_starts_with($redirect_uri, 'file:') || str_starts_with($redirect_uri, 'scp:')) {
throw new \RuntimeException('Curl redirect cannot be used in file or scp requests.');
}

$response = $this->request($method, $redirect_uri, $data, $headers, $timeout, $userAgent);

Check failure on line 206 in src/Transport/Curl.php

View workflow job for this annotation

GitHub Actions / Run PHPstan

Parameter #2 $uri of method Joomla\Http\Transport\Curl::request() expects Joomla\Uri\UriInterface, string given.
}

return $response;
}

/**
Expand Down Expand Up @@ -327,6 +349,13 @@
*/
private function redirectsAllowed(): bool
{
return true;
$curlVersion = curl_version();

// If open_basedir is enabled we also need to check if libcurl version is 7.19.4 or higher
if (!\ini_get('open_basedir') || version_compare($curlVersion['version'], '7.19.4', '>=')) {
return true;
}

return false;
}
}
1 change: 1 addition & 0 deletions src/Transport/Stream.php
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,7 @@ public function request(
'http' => $options,
'ssl' => [
'verify_peer' => true,
'cafile' => $this->getOption('stream.certpath', CaBundle::getBundledCaBundlePath()),
'verify_depth' => 5,
'verify_peer_name' => true,
],
Expand Down
Loading