Skip to content
This repository was archived by the owner on Sep 22, 2022. It is now read-only.

Commit 2e10ae4

Browse files
committed
Fix php-curl-class#240: Make CURLINFO_HEADER_OUT optional.
CURLINFO_HEADER_OUT is true by default, but now optional. When CURLINFO_HEADER_OUT is not true, requestHeaders will be null.
1 parent 97cb91e commit 2e10ae4

File tree

2 files changed

+29
-12
lines changed

2 files changed

+29
-12
lines changed

src/Curl/Curl.php

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
class Curl
66
{
7-
const VERSION = '4.6.9';
7+
const VERSION = '4.7.0';
88
const DEFAULT_TIMEOUT = 30;
99

1010
public $curl;
@@ -313,7 +313,11 @@ public function exec($ch = null)
313313
$this->error = $this->curlError || $this->httpError;
314314
$this->errorCode = $this->error ? ($this->curlError ? $this->curlErrorCode : $this->httpStatusCode) : 0;
315315

316-
$this->requestHeaders = $this->parseRequestHeaders(curl_getinfo($this->curl, CURLINFO_HEADER_OUT));
316+
// NOTE: CURLINFO_HEADER_OUT set to true is required for requestHeaders
317+
// to not be empty (e.g. $curl->setOpt(CURLINFO_HEADER_OUT, true);).
318+
if ($this->getOpt(CURLINFO_HEADER_OUT) === true) {
319+
$this->requestHeaders = $this->parseRequestHeaders(curl_getinfo($this->curl, CURLINFO_HEADER_OUT));
320+
}
317321
$this->responseHeaders = $this->parseResponseHeaders($this->rawResponseHeaders);
318322
list($this->response, $this->rawResponse) = $this->parseResponse($this->responseHeaders, $this->rawResponse);
319323

@@ -693,7 +697,6 @@ public function setJsonDecoder($function)
693697
public function setOpt($option, $value)
694698
{
695699
$required_options = array(
696-
CURLINFO_HEADER_OUT => 'CURLINFO_HEADER_OUT',
697700
CURLOPT_RETURNTRANSFER => 'CURLOPT_RETURNTRANSFER',
698701
);
699702

tests/PHPCurlClass/PHPCurlClassTest.php

Lines changed: 23 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -830,6 +830,29 @@ public function testResponseHeaderCaseSensitivity()
830830
$this->assertEquals($etag, $response_headers['eTaG']);
831831
}
832832

833+
public function testHeaderOutOptional()
834+
{
835+
// CURLINFO_HEADER_OUT is true by default.
836+
$test_1 = new Test();
837+
$test_1->server('response_header', 'GET');
838+
$this->assertNotEmpty($test_1->curl->requestHeaders);
839+
$this->assertNotEmpty($test_1->curl->requestHeaders['Request-Line']);
840+
841+
// CURLINFO_HEADER_OUT is set to true.
842+
$test_2 = new Test();
843+
$test_2->curl->setOpt(CURLINFO_HEADER_OUT, true);
844+
$test_2->server('response_header', 'GET');
845+
$this->assertNotEmpty($test_2->curl->requestHeaders);
846+
$this->assertNotEmpty($test_2->curl->requestHeaders['Request-Line']);
847+
848+
// CURLINFO_HEADER_OUT is set to false.
849+
$test_3 = new Test();
850+
$test_3->curl->setOpt(CURLINFO_HEADER_OUT, false);
851+
$test_3->curl->verbose();
852+
$test_3->server('response_header', 'GET');
853+
$this->assertNull($test_3->curl->requestHeaders);
854+
}
855+
833856
public function testHeaderRedirect()
834857
{
835858
$test = new Test();
@@ -2384,15 +2407,6 @@ public function testClose()
23842407
$this->assertFalse(is_resource($curl->curl));
23852408
}
23862409

2387-
/**
2388-
* @expectedException PHPUnit_Framework_Error_Warning
2389-
*/
2390-
public function testRequiredOptionCurlInfoHeaderOutEmitsWarning()
2391-
{
2392-
$curl = new Curl();
2393-
$curl->setOpt(CURLINFO_HEADER_OUT, false);
2394-
}
2395-
23962410
/**
23972411
* @expectedException PHPUnit_Framework_Error_Warning
23982412
*/

0 commit comments

Comments
 (0)