From 24f033f9c90b4fc84ae8dd31e55b02ac4126585b Mon Sep 17 00:00:00 2001 From: Dominik Schilling Date: Thu, 28 Jul 2016 22:20:22 +0200 Subject: [PATCH] Transport: Add support for custom HTTP methods when using cURL. --- library/Requests/Transport/cURL.php | 5 +++++ tests/Transport/Base.php | 18 ++++++++++++++++++ 2 files changed, 23 insertions(+) diff --git a/library/Requests/Transport/cURL.php b/library/Requests/Transport/cURL.php index 36cba510c..f76606df6 100644 --- a/library/Requests/Transport/cURL.php +++ b/library/Requests/Transport/cURL.php @@ -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 diff --git a/tests/Transport/Base.php b/tests/Transport/Base.php index e9ca30f10..1db5035a6 100644 --- a/tests/Transport/Base.php +++ b/tests/Transport/Base.php @@ -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);