Skip to content

Commit

Permalink
Transport: Add support for custom HTTP methods when using cURL.
Browse files Browse the repository at this point in the history
  • Loading branch information
ocean90 committed Jul 31, 2016
1 parent 17c15b0 commit 24f033f
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 0 deletions.
5 changes: 5 additions & 0 deletions library/Requests/Transport/cURL.php
Original file line number Diff line number Diff line change
Expand Up @@ -347,6 +347,11 @@ protected function setup_handle($url, $headers, $data, $options) {
case Requests::TRACE:
curl_setopt($this->handle, CURLOPT_CUSTOMREQUEST, $options['type']);
break;
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
18 changes: 18 additions & 0 deletions tests/Transport/Base.php
Original file line number Diff line number Diff line change
Expand Up @@ -268,6 +268,24 @@ public function testDELETEWithData() {
$this->assertEquals(array('test' => 'true', 'test2' => 'test'), $result['args']);
}

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

public function testPURGEWithData() {
$data = array(
'test' => 'true',
'test2' => 'test',
);
$request = Requests::request(httpbin('/purge'), array(), $data, 'PURGE', array_merge(array('data_format'=>'query'),$this->getOptions()));
$this->assertEquals(200, $request->status_code);

$result = json_decode($request->body, true);
$this->assertEquals(httpbin('/purge?test=true&test2=test'), $result['url']);
$this->assertEquals(array('test' => 'true', 'test2' => 'test'), $result['args']);
}

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

0 comments on commit 24f033f

Please sign in to comment.