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

Update Curl.php #7405

Merged
merged 2 commits into from
Jun 12, 2017
Merged

Update Curl.php #7405

merged 2 commits into from
Jun 12, 2017

Conversation

redelschaap
Copy link
Contributor

@redelschaap redelschaap commented Nov 11, 2016

Added support for PUT requests

Added support for PUT requests
@@ -175,6 +175,9 @@ public function write($method, $url, $http_ver = '1.1', $headers = [], $body = '
if ($method == \Zend_Http_Client::POST) {
curl_setopt($this->_getResource(), CURLOPT_POST, true);
curl_setopt($this->_getResource(), CURLOPT_POSTFIELDS, $body);
} elseif ($method == \Zend_Http_Client::PUT) {
curl_setopt($this->_getResource(), CURLOPT_CUSTOMREQUEST, 'PUT');
Copy link
Member

Choose a reason for hiding this comment

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

There's a CURLOPT_PUT constant and with PUT requests you should be using CURLOPT_INFILE and CURLOPT_INFILESIZE.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The CURLOPT_PUT option was deprecated a couple versions of cURL ago (source), but the php.net documentation hasn't been updated yet. We verified this; when using the CURLOPT_PUT option, cURL was using GET instead of PUT.

Also, a lot APIs use the PUT method for other purposes than uploading files (only), for example to update an object rather than creating one. In that case CURLOPT_POSTFIELDS should be used. If uploading files via PUT requests does not use the CURLOPT_POSTFIELDS option, the function Curl::write() method should be modified imho, e.g. with an extra parameter.

I haven't tested this myself, but I think CURLFile can be used in combination with PUT requests too.

Copy link
Member

Choose a reason for hiding this comment

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

I stand corrected as to the deprecation, but in that case the recommendation is to use CURLOPT_UPLOAD, it will automatically assume the HTTP PUT method unless otherwise specified, and then you then still have the ability to handle CURLOPT_INFILESIZE or CURLOPT_INFILESIZE_LARGE.

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 agree, but keep in mind that PUT has other use cases than uploading files only.

We noticed that `CURLOPT_CUSTOMREQUEST` has priority over regular options like `CURLOPT_HTTPGET` and `CURLOPT_POST`. When the `CURLOPT_CUSTOMREQUEST` option has been set to `PUT` for a PUT request, `CURLOPT_HTTPGET` and `CURLOPT_POST` do not overwrite the value of `CURLOPT_CUSTOMREQUEST` and thus `CURLOPT_CUSTOMREQUEST` has to be used again.
@maghamed maghamed self-requested a review February 22, 2017 19:14
@maghamed maghamed self-assigned this Feb 22, 2017
@okorshenko okorshenko added this to the March 2017 milestone Mar 1, 2017
@okorshenko okorshenko modified the milestones: March 2017, April 2017 Apr 2, 2017
@okorshenko okorshenko modified the milestones: April 2017, May 2017 May 9, 2017
@okorshenko okorshenko modified the milestones: May 2017, June 2017 Jun 1, 2017
@ishakhsuvarov ishakhsuvarov self-assigned this Jun 8, 2017
@magento-team magento-team merged commit 2b9a6b3 into magento:develop Jun 12, 2017
magento-team pushed a commit that referenced this pull request Jun 12, 2017
@redelschaap redelschaap deleted the patch-2 branch June 13, 2017 07:31
magento-devops-reposync-svc pushed a commit that referenced this pull request Apr 12, 2022
B2B-2148: Can no longer install when my database name has a dash in it
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

6 participants