Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add CURLINFO_PRIVATE to CurlHelper #285

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
8 changes: 8 additions & 0 deletions src/VCR/LibraryHooks/CurlHook.php
Original file line number Diff line number Diff line change
Expand Up @@ -296,6 +296,14 @@ public static function curlMultiInfoRead()
*/
public static function curlGetinfo($curlHandle, $option = 0)
{
// Workaround for CURLINFO_PRIVATE.
// It can be set AND read before the response is available, e.g by symfony/http-client.
// - If the response is available, we read from it.
// - If not, we return what was first set.
if ($option === CURLINFO_PRIVATE && !in_array((int) $curlHandle, self::$responses, true)) {
return static::$curlOptions[(int) $curlHandle][CURLOPT_PRIVATE];
}

return CurlHelper::getCurlOptionFromResponse(
self::$responses[(int) $curlHandle],
$option
Expand Down
16 changes: 16 additions & 0 deletions tests/VCR/LibraryHooks/CurlHookTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,22 @@ public function testShouldReturnCurlInfoAll()
$this->curlHook->disable();
}

public function testShouldHandleCurlOptPrivate()
{
$this->curlHook->enable($this->getTestCallback());

$curlHandle = curl_init('http://example.com');
curl_setopt($curlHandle, CURLOPT_PRIVATE, 'private');

$this->assertEquals('private', curl_getinfo($curlHandle, CURLINFO_PRIVATE));

curl_exec($curlHandle);
curl_close($curlHandle);

$this->assertEquals('private', curl_getinfo($curlHandle, CURLINFO_PRIVATE));
$this->curlHook->disable();
}

public function testShouldReturnCurlInfoAllKeys()
{
$this->curlHook->enable($this->getTestCallback());
Expand Down
6 changes: 3 additions & 3 deletions tests/VCR/RequestTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -219,9 +219,9 @@ public function testGetHostReturnsBothHostAndPort()
public function testDoNotOverwriteHostHeader()
{
$this->request = new Request(
'GET',
'http://example.com',
array('User-Agent' => 'Unit-Test', 'Host' => 'www.example.com')
'GET',
'http://example.com',
array('User-Agent' => 'Unit-Test', 'Host' => 'www.example.com')
);

$this->assertEquals(
Expand Down