Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

Use existing curl_opt equest methods instead of custom request #283

Merged
merged 1 commit into from

3 participants

@Ikke
Collaborator

For POST and PUT, use the existing curlopt options instead of
custom_request.

Fixes #4515

@Ikke Ikke Use existing curl_opt equest methods instead of custom request
For POST and PUT, use the existing curlopt options instead of
custom_request.

Fixes #4515
707bd27
@Yahasana Yahasana commented on the diff
classes/kohana/request/client/curl.php
@@ -24,8 +24,10 @@ public function _send_message(Request $request)
// Response headers
$response_headers = array();
+ $options = array();
@Yahasana
Yahasana added a note

these two lines is unnecessary

@Ikke Collaborator
Ikke added a note

Although they aren't necessary, I do always add them for clarity. It tells someone reading the code there's going to be an array.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
@Yahasana Yahasana commented on the diff
classes/kohana/request/client/curl.php
@@ -107,4 +109,27 @@ public function _send_message(Request $request)
return $response;
}
+ /**
+ * Sets the appropriate curl request options. Uses the responding options
+ * for POST and PUT, uses CURLOPT_CUSTOMREQUEST otherwise
+ * @param Request $request
+ * @param array $options
+ * @return array
+ */
+ public function _set_curl_request_method(Request $request, array $options)
@Yahasana
Yahasana added a note

if it's public, shouldn't start with _

@Ikke Collaborator
Ikke added a note

I'm just following the style of this file. Most methods that start with a _ are public.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
@Yahasana Yahasana commented on the diff
classes/kohana/request/client/curl.php
((6 lines not shown))
// Set the request method
- $options[CURLOPT_CUSTOMREQUEST] = $request->method();
+ $options = $this->_set_curl_request_method($request, $options);
@Yahasana
Yahasana added a note

CURLOPT_CUSTOMREQUEST is ok for things like "GET", "POST","PUT", "DELETE", "CONNECT" and so on

@Ikke Collaborator
Ikke added a note

If you read the issue linked to this pull request, you'll see that it actually gave a problem to someone.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
@Zeelot Zeelot merged commit 94d135c into kohana:3.2/develop
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Aug 5, 2012
  1. @Ikke

    Use existing curl_opt equest methods instead of custom request

    Ikke authored
    For POST and PUT, use the existing curlopt options instead of
    custom_request.
    
    Fixes #4515
This page is out of date. Refresh to see the latest.
Showing with 26 additions and 1 deletion.
  1. +26 −1 classes/kohana/request/client/curl.php
View
27 classes/kohana/request/client/curl.php
@@ -24,8 +24,10 @@ public function _send_message(Request $request)
// Response headers
$response_headers = array();
+ $options = array();
@Yahasana
Yahasana added a note

these two lines is unnecessary

@Ikke Collaborator
Ikke added a note

Although they aren't necessary, I do always add them for clarity. It tells someone reading the code there's going to be an array.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
+
// Set the request method
- $options[CURLOPT_CUSTOMREQUEST] = $request->method();
+ $options = $this->_set_curl_request_method($request, $options);
@Yahasana
Yahasana added a note

CURLOPT_CUSTOMREQUEST is ok for things like "GET", "POST","PUT", "DELETE", "CONNECT" and so on

@Ikke Collaborator
Ikke added a note

If you read the issue linked to this pull request, you'll see that it actually gave a problem to someone.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
// Set the request body. This is perfectly legal in CURL even
// if using a request other than POST. PUT does support this method
@@ -107,4 +109,27 @@ public function _send_message(Request $request)
return $response;
}
+ /**
+ * Sets the appropriate curl request options. Uses the responding options
+ * for POST and PUT, uses CURLOPT_CUSTOMREQUEST otherwise
+ * @param Request $request
+ * @param array $options
+ * @return array
+ */
+ public function _set_curl_request_method(Request $request, array $options)
@Yahasana
Yahasana added a note

if it's public, shouldn't start with _

@Ikke Collaborator
Ikke added a note

I'm just following the style of this file. Most methods that start with a _ are public.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
+ {
+ switch ($request->method()) {
+ case Request::POST:
+ $options[CURLOPT_POST] = TRUE;
+ break;
+ case Request::PUT:
+ $options[CURLOPT_PUT] = TRUE;
+ break;
+ default:
+ $options[CURLOPT_CUSTOMREQUEST] = $request->method();
+ break;
+ }
+ return $options;
+ }
+
} // End Kohana_Request_Client_Curl
Something went wrong with that request. Please try again.