Skip to content

Commit

Permalink
Merge pull request #2168 from MGatner/curl-debug-bug
Browse files Browse the repository at this point in the history
Fix for CURL for 'debug' option
  • Loading branch information
lonnieezell authored Sep 17, 2019
2 parents bf89f37 + 1660ed0 commit 4353f47
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 5 deletions.
6 changes: 3 additions & 3 deletions system/HTTP/CURLRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -672,10 +672,10 @@ protected function setCURLOptions(array $curl_options = [], array $config = [])
}

// Debug
if (isset($config['debug']))
if ($config['debug'])
{
$curl_options[CURLOPT_VERBOSE] = $config['debug'] === true ? 1 : 0;
$curl_options[CURLOPT_STDERR] = $config['debug'] === true ? fopen('php://output', 'w+') : $config['debug'];
$curl_options[CURLOPT_VERBOSE] = 1;
$curl_options[CURLOPT_STDERR] = is_string($config['debug']) ? fopen($config['debug'], 'a+') : fopen('php://output', 'w+');
}

// Decode Content
Expand Down
25 changes: 23 additions & 2 deletions tests/system/HTTP/CURLRequestTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -448,7 +448,7 @@ public function testSSLWithBadKey()

//--------------------------------------------------------------------

public function testDebugOption()
public function testDebugOptionTrue()
{
$this->request->request('get', 'http://example.com', [
'debug' => true,
Expand All @@ -461,14 +461,35 @@ public function testDebugOption()

$this->assertArrayHasKey(CURLOPT_STDERR, $options);
$this->assertTrue(is_resource($options[CURLOPT_STDERR]));
}

public function testDebugOptionFalse()
{
$this->request->request('get', 'http://example.com', [
'debug' => false,
]);

$options = $this->request->curl_options;

$this->assertFalse($options[CURLOPT_STDERR]);
$this->assertArrayNotHasKey(CURLOPT_VERBOSE, $options);
$this->assertArrayNotHasKey(CURLOPT_STDERR, $options);
}

public function testDebugOptionFile()
{
$file = SUPPORTPATH . 'Files/baker/banana.php';

$this->request->request('get', 'http://example.com', [
'debug' => $file,
]);

$options = $this->request->curl_options;

$this->assertArrayHasKey(CURLOPT_VERBOSE, $options);
$this->assertEquals(1, $options[CURLOPT_VERBOSE]);

$this->assertArrayHasKey(CURLOPT_STDERR, $options);
$this->assertTrue(is_resource($options[CURLOPT_STDERR]));
}

//--------------------------------------------------------------------
Expand Down

0 comments on commit 4353f47

Please sign in to comment.