Permalink
Browse files

Added support for all HTTP methods when creating external requests

  • Loading branch information...
1 parent 2f639b8 commit 3159a51ae46299572da960aef6b85853d2a0750e Sam de Freyssinet committed Feb 7, 2010
Showing with 22 additions and 4 deletions.
  1. +10 −0 classes/kohana/remote.php
  2. +12 −4 classes/kohana/request.php
View
@@ -11,6 +11,16 @@
*/
class Kohana_Remote {
+ // Request types
+ const CONNECT = 'CONNECT';
+ const DELETE = 'DELETE';
+ const GET = 'GET';
+ const HEAD = 'HEAD';
+ const POST = 'POST';
+ const PUT = 'PUT';
+ const OPTIONS = 'OPTIONS';
+ const TRACE = 'TRACE';
+
// Default curl options
public static $default_options = array
(
View
@@ -861,13 +861,15 @@ public function send_file($filename, $download = NULL, array $options = NULL)
* By default, the output from the controller is captured and returned, and
* no headers are sent.
*
+ * @param array Additional headers to send with the request
+ * @param string The HTTP method to use
* @return $this
*/
- public function execute(array $http_headers = array())
+ public function execute(array $http_headers = array(), $method = NULL)
{
// If this is an external request, process it as such
if ($this->external)
- return $this->external_execute($http_headers);
+ return $this->external_execute($http_headers, $method);
// Create the class prefix
$prefix = 'controller_';
@@ -1002,18 +1004,24 @@ public function check_cache($etag = null)
/**
* Execute a request that is to an external source
*
- * @return self
+ * @param array Additional headers to send with the request
+ * @param string The HTTP method to use
+ * @return $this
*/
- protected function external_execute(array $request_headers = array())
+ protected function external_execute(array $request_headers = array(), $method = NULL)
{
// Start benchmarking if required
if (Kohana::$profiling === TRUE)
$benchmark = Profiler::start('External Requests', $this->uri);
+ if (NULL === $method)
+ $method = Remote::GET;
+
// Get the resonse status
$this->status = Remote::status($this->uri);
$this->response = Remote::get($this->uri, array(
CURLOPT_HTTPHEADER => $request_headers,
+ CURLOPT_CUSTOMREQUEST => $method,
));
$this->headers = Remote::$headers;

0 comments on commit 3159a51

Please sign in to comment.