Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
545 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -41,7 +41,7 @@ public function __invoke( | |
unset($conf['_headers']); | ||
// Add handler options from the request configuration options | ||
if (isset($options['curl'])) { | ||
$options = $this->applyCustomCurlOptions($options['curl'], $conf); | ||
$conf = $this->applyCustomCurlOptions($options['curl'], $conf); | ||
} | ||
|
||
if (!$handle) { | ||
|
@@ -211,7 +211,7 @@ private function applyMethod(RequestInterface $request, array $options, array &$ | |
$body = $request->getBody(); | ||
$size = $body->getSize(); | ||
|
||
if ($size !== null && $size > 0) { | ||
if ($size === null || $size > 0) { | ||
This comment has been minimized.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong.
mtdowling
Author
Member
|
||
$this->applyBody($request, $options, $conf); | ||
return; | ||
} | ||
|
@@ -237,13 +237,14 @@ private function applyMethod(RequestInterface $request, array $options, array &$ | |
|
||
private function applyBody(RequestInterface $request, array $options, array &$conf) | ||
{ | ||
$contentLength = $request->getHeader('Content-Length'); | ||
$size = $contentLength !== null ? (int) $contentLength : null; | ||
$size = $request->hasHeader('Content-Length') | ||
? (int) $request->getHeader('Content-Length') | ||
: $request->getBody()->getSize(); | ||
|
||
// Send the body as a string if the size is less than 1MB OR if the | ||
// [client][curl][body_as_string] request value is set. | ||
// [curl][body_as_string] request value is set. | ||
if (($size !== null && $size < 1000000) || | ||
isset($options['curl']['body_as_string']) | ||
!empty($options['curl']['body_as_string']) | ||
) { | ||
$conf[CURLOPT_POSTFIELDS] = (string) $request->getBody(); | ||
// Don't duplicate the Content-Length header | ||
|
@@ -303,7 +304,7 @@ private function applyHeaders(RequestInterface $request, array &$conf) | |
* Takes an array of curl options specified in the 'curl' option of a | ||
* request's configuration array and maps them to CURLOPT_* options. | ||
* | ||
* This method is only called when a request has a 'curl' config setting. | ||
* This method is only called when a request has a 'curl' config setting. | ||
* | ||
* @param array $options Configuration array of custom curl option | ||
* @param array $conf Array of existing curl options | ||
|
@@ -436,8 +437,7 @@ function ($ch, $write) use ($value) { | |
|
||
if (!is_array($value)) { | ||
$conf[CURLOPT_PROXY] = $value; | ||
} elseif (isset($request['scheme'])) { | ||
$scheme = $request['scheme']; | ||
} elseif ($scheme = $request->getUri()->getScheme()) { | ||
if (isset($value[$scheme])) { | ||
$conf[CURLOPT_PROXY] = $value[$scheme]; | ||
} | ||
|
@@ -529,7 +529,7 @@ private static function retryFailedRewind( | |
array $options, | ||
array $response | ||
) { | ||
if ($request->getBody()->rewind()) { | ||
if (!$request->getBody()->rewind()) { | ||
$response['err_message'] = 'The connection unexpectedly failed ' | ||
. 'without providing an error. The request would have been ' | ||
. 'retried, but attempting to rewind the request body failed.'; | ||
|
@@ -541,7 +541,7 @@ private static function retryFailedRewind( | |
$options['curl']['retries'] = 1; | ||
} elseif ($options['curl']['retries'] == 2) { | ||
$response['err_message'] = 'The cURL request was retried 3 times ' | ||
. 'and did no succeed. cURL was unable to rewind the body of ' | ||
. 'and did not succeed. cURL was unable to rewind the body of ' | ||
. 'the request and subsequent retries resulted in the same ' | ||
. 'error. Turn on the debug option to see what went wrong. ' | ||
. 'See https://bugs.php.net/bug.php?id=47204 for more information.'; | ||
|
Oops, something went wrong.
Hi!
Is this the expected behavior ? I find it odd that the body is being applied when its size is not set / null ; I imagine there is a reason, but couldn't figure it out from the code.
(I'm debugging an issue I have with PHP-VCR that fails when curl has the CURLOPT_READFUNCTION set without the CURLOPT_INFILESIZE)
Thanks in advance for any help/explanation.