Skip to content

Commit

Permalink
Merge pull request WordPress#227 from ocean90/curl-custom-http-methods
Browse files Browse the repository at this point in the history
cURL: Support custom HTTP methods
  • Loading branch information
rmccue committed Aug 4, 2016
2 parents 17c15b0 + aec05fe commit 1b5ffd8
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 7 deletions.
16 changes: 9 additions & 7 deletions library/Requests/Transport/cURL.php
Original file line number Diff line number Diff line change
Expand Up @@ -333,20 +333,22 @@ protected function setup_handle($url, $headers, $data, $options) {
curl_setopt($this->handle, CURLOPT_POST, true);
curl_setopt($this->handle, CURLOPT_POSTFIELDS, $data);
break;
case Requests::PATCH:
case Requests::PUT:
case Requests::DELETE:
case Requests::OPTIONS:
curl_setopt($this->handle, CURLOPT_CUSTOMREQUEST, $options['type']);
curl_setopt($this->handle, CURLOPT_POSTFIELDS, $data);
break;
case Requests::HEAD:
curl_setopt($this->handle, CURLOPT_CUSTOMREQUEST, $options['type']);
curl_setopt($this->handle, CURLOPT_NOBODY, true);
break;
case Requests::TRACE:
curl_setopt($this->handle, CURLOPT_CUSTOMREQUEST, $options['type']);
break;
case Requests::PATCH:
case Requests::PUT:
case Requests::DELETE:
case Requests::OPTIONS:
default:
curl_setopt($this->handle, CURLOPT_CUSTOMREQUEST, $options['type']);
if (!empty($data)) {
curl_setopt($this->handle, CURLOPT_POSTFIELDS, $data);
}
}

// cURL requires a minimum timeout of 1 second when using the system
Expand Down
17 changes: 17 additions & 0 deletions tests/Transport/Base.php
Original file line number Diff line number Diff line change
Expand Up @@ -268,6 +268,23 @@ public function testDELETEWithData() {
$this->assertEquals(array('test' => 'true', 'test2' => 'test'), $result['args']);
}

public function testLOCK() {
$request = Requests::request(httpbin('/lock'), array(), array(), 'LOCK', $this->getOptions());
$this->assertEquals(200, $request->status_code);
}

public function testLOCKWithData() {
$data = array(
'test' => 'true',
'test2' => 'test',
);
$request = Requests::request(httpbin('/lock'), array(), $data, 'LOCK', $this->getOptions());
$this->assertEquals(200, $request->status_code);

$result = json_decode($request->body, true);
$this->assertEquals(array('test' => 'true', 'test2' => 'test'), $result['form']);
}

public function testRedirects() {
$request = Requests::get(httpbin('/redirect/6'), array(), $this->getOptions());
$this->assertEquals(200, $request->status_code);
Expand Down

0 comments on commit 1b5ffd8

Please sign in to comment.