MDL-73588 curl: Fix expected CURLOPT_FILE behavior

After cbf9dfb the CURLOPT_FILE no longer behaves as expected. All
redirect responses are appended to the same stream resource.  This fix
reverts back to the old behavior by setting the stream pointer back to
the beginning for each subsequent redirect.
This commit is contained in:
Frode Petterson
2022-01-27 12:18:26 +01:00
committed by Eloy Lafuente (stronk7)
parent 996bea908e
commit 1a03e46f96
2 changed files with 41 additions and 0 deletions
+10
View File
@@ -3778,6 +3778,16 @@ class curl {
return $this->error;
}
// If the response body is written to a seekable stream resource, reset the stream pointer to avoid
// appending multiple response bodies to the same resource.
if (!empty($this->options['CURLOPT_FILE'])) {
$streammetadata = stream_get_meta_data($this->options['CURLOPT_FILE']);
if ($streammetadata['seekable']) {
ftruncate($this->options['CURLOPT_FILE'], 0);
rewind($this->options['CURLOPT_FILE']);
}
}
curl_setopt($curl, CURLOPT_URL, $redirecturl);
$ret = curl_exec($curl);