Skip to content

Commit 4353f47

Browse files
authored
Merge pull request #2168 from MGatner/curl-debug-bug
Fix for CURL for 'debug' option
2 parents bf89f37 + 1660ed0 commit 4353f47

2 files changed

Lines changed: 26 additions & 5 deletions

File tree

system/HTTP/CURLRequest.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -672,10 +672,10 @@ protected function setCURLOptions(array $curl_options = [], array $config = [])
672672
}
673673

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

681681
// Decode Content

tests/system/HTTP/CURLRequestTest.php

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -448,7 +448,7 @@ public function testSSLWithBadKey()
448448

449449
//--------------------------------------------------------------------
450450

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

462462
$this->assertArrayHasKey(CURLOPT_STDERR, $options);
463463
$this->assertTrue(is_resource($options[CURLOPT_STDERR]));
464+
}
464465

466+
public function testDebugOptionFalse()
467+
{
465468
$this->request->request('get', 'http://example.com', [
466469
'debug' => false,
467470
]);
468471

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

471-
$this->assertFalse($options[CURLOPT_STDERR]);
474+
$this->assertArrayNotHasKey(CURLOPT_VERBOSE, $options);
475+
$this->assertArrayNotHasKey(CURLOPT_STDERR, $options);
476+
}
477+
478+
public function testDebugOptionFile()
479+
{
480+
$file = SUPPORTPATH . 'Files/baker/banana.php';
481+
482+
$this->request->request('get', 'http://example.com', [
483+
'debug' => $file,
484+
]);
485+
486+
$options = $this->request->curl_options;
487+
488+
$this->assertArrayHasKey(CURLOPT_VERBOSE, $options);
489+
$this->assertEquals(1, $options[CURLOPT_VERBOSE]);
490+
491+
$this->assertArrayHasKey(CURLOPT_STDERR, $options);
492+
$this->assertTrue(is_resource($options[CURLOPT_STDERR]));
472493
}
473494

474495
//--------------------------------------------------------------------

0 commit comments

Comments
 (0)