diff --git a/dev/tests/integration/framework/Magento/TestFramework/Helper/Curl.php b/dev/tests/integration/framework/Magento/TestFramework/Helper/Curl.php index 62b753cf5d34..7a64ad385303 100644 --- a/dev/tests/integration/framework/Magento/TestFramework/Helper/Curl.php +++ b/dev/tests/integration/framework/Magento/TestFramework/Helper/Curl.php @@ -15,16 +15,15 @@ class Curl extends CurlLibrary /** * Make DELETE request * - * String type was added to parameter $param in order to support sending JSON or XML requests. - * This feature was added base on Community Pull Request https://github.com/magento/magento2/pull/8373 - * * @param string $uri + * @param array|string $params * @return void * - * @see \Magento\Framework\HTTP\Client#post($uri, $params) + * @deprecated Replace with the core `delete` implementation + * @see \Magento\Framework\HTTP\Client\Curl::delete */ - public function delete($uri) + public function delete($uri, array|string $params = []): void { - $this->makeRequest("DELETE", $uri); + $this->makeRequest("DELETE", $uri, $params); } } diff --git a/lib/internal/Magento/Framework/HTTP/Client/Curl.php b/lib/internal/Magento/Framework/HTTP/Client/Curl.php index 7ba4fb915e29..a5132ca740d9 100644 --- a/lib/internal/Magento/Framework/HTTP/Client/Curl.php +++ b/lib/internal/Magento/Framework/HTTP/Client/Curl.php @@ -1,9 +1,8 @@ * @SuppressWarnings(PHPMD.ExcessiveClassComplexity) * @api */ 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', + 'OPTIONS' + ]; + /** * Max supported protocol by curl CURL_SSLVERSION_TLSv1_2 * @var int @@ -223,6 +231,8 @@ public function removeCookies() * * @param string $uri uri relative to host, ex. "/index.php" * @return void + * + * @url https://www.rfc-editor.org/rfc/rfc9110.html#section-9.3.1 */ public function get($uri) { @@ -239,13 +249,109 @@ public function get($uri) * @param array|string $params * @return void * - * @see \Magento\Framework\HTTP\Client#post($uri, $params) + * @see \Magento\Framework\HTTP\Client::post($uri, $params) + * @url https://www.rfc-editor.org/rfc/rfc9110.html#section-9.3.3 */ public function post($uri, $params) { $this->makeRequest("POST", $uri, $params); } + /** + * Make PUT request + * + * @param string $uri + * @param array|string $params + * @return void + * + * @url https://www.rfc-editor.org/rfc/rfc9110.html#section-9.3.4 + */ + public function put(string $uri, string|array $params): void + { + $this->makeRequest("PUT", $uri, $params); + } + + /** + * Make DELETE request + * + * @param string $uri + * @param array|string $params + * @return void + * + * @url https://www.rfc-editor.org/rfc/rfc9110.html#section-9.3.5 + */ + public function delete($uri, array|string $params = []): void + { + $this->makeRequest("DELETE", $uri, $params); + } + + /** + * Make PATCH request + * + * @param string $uri + * @param array|string $params + * @return void + * + * @url https://www.rfc-editor.org/info/rfc5789 + */ + public function patch(string $uri, array|string $params): void + { + $this->makeRequest("PATCH", $uri, $params); + } + + /** + * Make OPTIONS request + * + * @param string $uri + * @param array|string $params + * @return void + * + * @url https://www.rfc-editor.org/rfc/rfc9110.html#section-9.3.7 + */ + public function options(string $uri, array|string $params = []): void + { + $this->makeRequest("OPTIONS", $uri, $params); + } + + /** + * Make HEAD request + * + * @param string $uri + * @return void + * + * @url https://www.rfc-editor.org/rfc/rfc9110.html#section-9.3.2 + */ + public function head(string $uri): void + { + $this->makeRequest("HEAD", $uri); + } + + /** + * Make TRACE request + * + * @param string $uri + * @return void + * + * @url https://www.rfc-editor.org/rfc/rfc9110.html#section-9.3.8 + */ + public function trace(string $uri): void + { + $this->makeRequest("TRACE", $uri); + } + + /** + * Make CONNECT request + * + * @param string $uri + * @return void + * + * @url https://www.rfc-editor.org/rfc/rfc9110.html#section-9.3.6 + */ + public function connect(string $uri): void + { + $this->makeRequest("CONNECT", $uri); + } + /** * Get response headers * @@ -359,13 +465,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)) {