Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[2.5] Add support for missing Curl methods to the Curl client #39469

Open
wants to merge 3 commits into
base: 2.5-develop
Choose a base branch
from
Open
Changes from 1 commit
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
Prev Previous commit
Next Next commit
SwiftOtter-SOP-348 Pass HTTP payload curlopt
lbajsarowicz committed Dec 12, 2024
commit 4af7f36db1a7ffc31e9df177ed8ed27c42c10e69
34 changes: 28 additions & 6 deletions lib/internal/Magento/Framework/HTTP/Client/Curl.php
Original file line number Diff line number Diff line change
@@ -15,6 +15,17 @@
*/
class Curl implements \Magento\Framework\HTTP\ClientInterface
{
/**
* @url https://www.rfc-editor.org/rfc/rfc9110.html
*/
private const HTTP_METHODS_WITH_PAYLOAD = [
'POST',
'PUT',
'PATCH',
'DELETE',
'OPTIONS'
];

/**
* Max supported protocol by curl CURL_SSLVERSION_TLSv1_2
* @var int
@@ -455,13 +466,24 @@ protected function makeRequest($method, $uri, $params = [])
$this->_ch = curl_init();
$this->curlOption(CURLOPT_PROTOCOLS, CURLPROTO_HTTP | CURLPROTO_HTTPS | CURLPROTO_FTP | CURLPROTO_FTPS);
$this->curlOption(CURLOPT_URL, $uri);
if ($method == 'POST') {
$this->curlOption(CURLOPT_POST, 1);

if (in_array($method, self::HTTP_METHODS_WITH_PAYLOAD)) {
$this->curlOption(CURLOPT_POSTFIELDS, is_array($params) ? http_build_query($params) : $params);
} elseif ($method == "GET") {
$this->curlOption(CURLOPT_HTTPGET, 1);
} else {
$this->curlOption(CURLOPT_CUSTOMREQUEST, $method);
}

switch ($method) {
case 'POST':
$this->curlOption(CURLOPT_POST, 1);
break;
case 'PUT':
$this->curlOption(CURLOPT_PUT, 1);
break;
case "GET":
$this->curlOption(CURLOPT_HTTPGET, 1);
break;
default:
$this->curlOption(CURLOPT_CUSTOMREQUEST, $method);
break;
}

if (count($this->_headers)) {