Skip to content

Commit

Permalink
Add PATCH support. See #2, still awaiting tests.
Browse files Browse the repository at this point in the history
Unable to add tests at the moment, as httpbin's /patch endpoint is broken and refuses to accept PATCH requests
  • Loading branch information
rmccue committed Feb 8, 2012
1 parent 329432f commit 48dc511
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 1 deletion.
20 changes: 20 additions & 0 deletions library/Requests.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,14 @@ class Requests {
*/
const DELETE = 'DELETE';

/**
* PATCH method
*
* @link http://tools.ietf.org/html/rfc5789
* @var string
*/
const PATCH = 'PATCH';

/**
* Current version of Requests
*
Expand Down Expand Up @@ -221,6 +229,18 @@ public static function post($url, $headers = array(), $data = array(), $options
public static function put($url, $headers = array(), $data = array(), $options = array()) {
return self::request($url, $headers, $data, self::PUT, $options);
}

/**
* Send a PATCH request
*
* Note: Unlike {@see post} and {@see put}, `$headers` is required, as the
* specification recommends that should send an ETag
*
* @link http://tools.ietf.org/html/rfc5789
*/
public static function patch($url, $headers, $data = array(), $options = array()) {
return self::request($url, $headers, $data, self::PATCH, $options);
}
/**#@-*/

/**
Expand Down
3 changes: 2 additions & 1 deletion library/Requests/Transport/cURL.php
Original file line number Diff line number Diff line change
Expand Up @@ -89,8 +89,9 @@ public function request($url, $headers = array(), $data = array(), $options = ar
curl_setopt($this->fp, CURLOPT_POST, true);
curl_setopt($this->fp, CURLOPT_POSTFIELDS, $data);
break;
case Requests::PATCH:
case Requests::PUT:
curl_setopt($this->fp, CURLOPT_CUSTOMREQUEST, 'PUT');
curl_setopt($this->fp, CURLOPT_CUSTOMREQUEST, $options['type']);
curl_setopt($this->fp, CURLOPT_POSTFIELDS, $data);
break;
case Requests::DELETE:
Expand Down
1 change: 1 addition & 0 deletions library/Requests/Transport/fsockopen.php
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ public function request($url, $headers = array(), $data = array(), $options = ar
switch ($options['type']) {
case Requests::POST:
case Requests::PUT:
case Requests::PATCH:
if (isset($url_parts['path'])) {
$path = $url_parts['path'];
if (isset($url_parts['query'])) {
Expand Down

0 comments on commit 48dc511

Please sign in to comment.