Skip to content

Commit

Permalink
Merge a380ca8 into 41f5321
Browse files Browse the repository at this point in the history
  • Loading branch information
Tjeerd committed Nov 12, 2019
2 parents 41f5321 + a380ca8 commit 6a350ad
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 3 deletions.
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
10 changes: 7 additions & 3 deletions src/VCR/Util/CurlHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,10 @@ public static function getCurlOptionFromResponse(Response $response, $option = 0
case CURLINFO_HEADER_SIZE:
$info = mb_strlen(HttpUtil::formatAsStatusWithHeadersString($response), 'ISO-8859-1');
break;
case CURLINFO_CERTINFO:
$curlInfo = $response->getCurlInfo($option);
$info = (!is_null($curlInfo)) ? $curlInfo : [];
break;
default:
$info = $response->getCurlInfo($option);
break;
Expand Down Expand Up @@ -187,7 +191,7 @@ public static function setCurlOptionOnRequest(Request $request, $option, $value,
break;
}
}

/**
* Makes sure we've properly handled the POST body, such as ensuring that
* CURLOPT_INFILESIZE is set if CURLOPT_READFUNCTION is set.
Expand All @@ -201,13 +205,13 @@ public static function validateCurlPOSTBody(Request $request, $curlHandle = null
if (is_null($readFunction)) {
return;
}

// Guzzle 4 sometimes sets the post body in CURLOPT_POSTFIELDS even if
// they have already set CURLOPT_READFUNCTION.
if ($request->getBody()) {
return;
}

$bodySize = $request->getCurlOption(CURLOPT_INFILESIZE);
Assertion::notEmpty($bodySize, 'To set a CURLOPT_READFUNCTION, CURLOPT_INFILESIZE must be set.');
$body = call_user_func_array($readFunction, array($curlHandle, fopen('php://memory', 'r'), $bodySize));
Expand Down

0 comments on commit 6a350ad

Please sign in to comment.