Skip to content

Add missing REST methods to Curl Client (SwiftOtter's SOP-348) #39330

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

Closed
Show file tree
Hide file tree
Changes from 7 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
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
* Copyright 2022 Adobe
* All Rights Reserved.
*/
declare(strict_types=1);

namespace Magento\TestModuleCatalogSearch\Model;

use Magento\Framework\App\Config\ScopeConfigInterface;
use Magento\TestFramework\Helper\Bootstrap;
use Magento\TestFramework\Helper\Curl;
use Magento\Framework\HTTP\Client\Curl;

/**
* Retrieve search engine version by curl request
Expand Down
Original file line number Diff line number Diff line change
@@ -1,24 +1,25 @@
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
* Copyright 2018 Adobe
* All Rights Reserved.
*/

declare(strict_types=1);

namespace Magento\TestFramework\Helper;

use Magento\Framework\HTTP\Client\Curl;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In line no. 53:

$this->curl = new Curl();

I suggest you add the parameter $curl as null and use ObjectManager to initialize it. Please refer to the $this->deploymentConfig


/**
* Helper class to access RabbitMQ server configuration
*/
class Amqp
{
const CONFIG_PATH_HOST = 'queue/amqp/host';
const CONFIG_PATH_USER = 'queue/amqp/user';
const CONFIG_PATH_PASSWORD = 'queue/amqp/password';
const DEFAULT_MANAGEMENT_PROTOCOL = 'http';
const DEFAULT_MANAGEMENT_PORT = '15672';
const DEFAULT_VIRTUALHOST = '/';
public const CONFIG_PATH_HOST = 'queue/amqp/host';
public const CONFIG_PATH_USER = 'queue/amqp/user';
public const CONFIG_PATH_PASSWORD = 'queue/amqp/password';
public const DEFAULT_MANAGEMENT_PROTOCOL = 'http';
public const DEFAULT_MANAGEMENT_PORT = '15672';
public const DEFAULT_VIRTUALHOST = '/';

/**
* @var Curl
Expand Down

This file was deleted.

89 changes: 85 additions & 4 deletions lib/internal/Magento/Framework/HTTP/Client/Curl.php
Original file line number Diff line number Diff line change
@@ -1,17 +1,15 @@
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
* Copyright 2011 Adobe
* All Rights Reserved.
*/

declare(strict_types=1);

namespace Magento\Framework\HTTP\Client;

/**
* Class to work with HTTP protocol using curl library
*
* @author Magento Core Team <[email protected]>
* @SuppressWarnings(PHPMD.ExcessiveClassComplexity)
* @api
*/
Expand Down Expand Up @@ -246,6 +244,89 @@ public function post($uri, $params)
$this->makeRequest("POST", $uri, $params);
}

/**
* Make PUT request
*
* @param string $uri
* @param array|string $params
* @return void
*/
public function put($uri, $params)
{
$this->makeRequest("PUT", $uri, $params);
}

/**
* Make DELETE request
*
* @param string $uri
* @param array|string $params
* @return void
*/
public function delete(string $uri, array|string $params = [])
{
$this->makeRequest("DELETE", $uri, $params);
}

/**
* Make PATCH request
*
* @param string $uri
* @param array|string $params
* @return void
*/
public function patch($uri, $params)
{
$this->makeRequest("PATCH", $uri, $params);
}

/**
* Make OPTIONS request
*
* @param string $uri
* @param array|string $params
* @return void
*/
public function options(string $uri, array|string $params = [])
{
$this->makeRequest("OPTIONS", $uri, $params);
}

/**
* Make HEAD request
*
* @param string $uri
* @param array|string $params
* @return void
*/
public function head(string $uri, array|string $params = [])
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I did not introduce a payload here because according to RFC9110

The HEAD method is identical to GET except that the server MUST NOT send content in the response.

https://www.rfc-editor.org/rfc/rfc9110.html#section-9.3.2


You're absolutely correct that the RFC you linked doesn't explicitly forbid a payload for HEAD requests. However, it strongly discourages it and hints at the reasons why it's generally not used:

Semantic Ambiguity:

  • HEAD is for metadata: The core purpose of HEAD is to fetch metadata about a resource without retrieving the actual data. A payload in this context has no clearly defined meaning. What should the server do with the provided data? Unlike POST (create/update) or PUT (replace), HEAD doesn't have an inherent action associated with a payload.

  • Potential for Confusion: Including a payload with HEAD could lead to confusion and unpredictable behavior, as servers might interpret it in different ways. This ambiguity undermines the standardization that HTTP strives for.

Why GET can have a payload (though discouraged):

While GET requests can technically have a payload, it's generally discouraged for similar reasons to HEAD. The RFC states that a payload in a GET request "has no semantic meaning to the request." This means the server is free to ignore it.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hello @lbajsarowicz,

Thanks for the detailed explanation.

FYI, as mentioned in #39330 (review), I have added an optional payload for the DELETE, OPTIONS, and HEAD methods. Additionally, I have added the CONNECT method with an optional payload. If possible, could you please revert these changes, or let me know which methods, including HEAD, do not require an optional payload? Your input would be greatly appreciated.

Thanks again!

{
$this->makeRequest("HEAD", $uri, $params);
}

/**
* Make TRACE request
*
* @param string $uri
* @return void
*/
public function trace(string $uri)
{
$this->makeRequest("TRACE", $uri);
}

/**
* Make CONNECT request
*
* @param string $uri
* @param array|string $params
* @return void
*/
public function connect(string $uri, array|string $params = [])
{
$this->makeRequest("CONNECT", $uri, $params);
}

/**
* Get response headers
*
Expand Down