diff --git a/library/Requests/Transport/cURL.php b/library/Requests/Transport/cURL.php index 36cba510c..8ffcb1e5c 100644 --- a/library/Requests/Transport/cURL.php +++ b/library/Requests/Transport/cURL.php @@ -333,13 +333,6 @@ 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); @@ -347,6 +340,15 @@ protected function setup_handle($url, $headers, $data, $options) { 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 diff --git a/tests/Transport/Base.php b/tests/Transport/Base.php index e9ca30f10..5ddce18c1 100644 --- a/tests/Transport/Base.php +++ b/tests/Transport/Base.php @@ -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);