ID: 47204
User updated by: avb@php.net
Reported By: avb@php.net
Status: Open
Bug Type: cURL related
Operating System: Irrelevant
PHP Version: 5.2.8
New Comment:
The same problem without PHP callback, using CURLOPT_READDATA to read
request body from a file:
<?php
$ch = curl_init();
curl_setopt($ch, CURLOPT_POST, true);
// This should be some URL protected by HTTP digest auth!
curl_setopt($ch, CURLOPT_URL, 'http://www.example.com/digest/');
curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_DIGEST);
curl_setopt($ch, CURLOPT_USERPWD, 'user:password');
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Length: ' .
filesize('./postdata')));
curl_setopt($ch, CURLOPT_READDATA, fopen('./postdata', 'rb'));
if (!curl_exec($ch)) {
echo 'Error #' . curl_errno($ch) . ': ' . curl_error($ch);
}
?>
This also prints "Error #65: necessary data rewind wasn't possible"
Previous Comments:
------------------------------------------------------------------------
[2009-01-23 23:28:24] avb@php.net
Description:
------------
PHP's cURL extension allows using a callback for reading the request
body via CURLOPT_READFUNCTION, but it doesn't provide a way to set a
CURLOPT_IOCTLFUNCTION callback for rewinding the request body.
This rewinding may be needed when doing a POST or PUT HTTP request to
resource protected by Digest authentication.
Reproduce code:
---------------
<?php
$position = 0;
$data = 'foo=' . str_repeat('bar', 10000);
function read_callback($ch, $fd, $length)
{
global $position, $data;
if ($position >= strlen($data)) {
return '';
}
$string = substr($data, $position, $length);
$position += strlen($string);
return $string;
}
$ch = curl_init();
curl_setopt($ch, CURLOPT_POST, true);
// This should be some URL protected by HTTP digest auth!
curl_setopt($ch, CURLOPT_URL, 'http://www.example.com/digest/');
curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_DIGEST);
curl_setopt($ch, CURLOPT_USERPWD, 'user:password');
curl_setopt($ch, CURLOPT_READFUNCTION, 'read_callback');
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Length: ' .
strlen($data)));
if (!curl_exec($ch)) {
echo 'Error #' . curl_errno($ch) . ': ' . curl_error($ch);
}
?>
Expected result:
----------------
Request should proceed.
Actual result:
--------------
Error #65: necessary data rewind wasn't possible
------------------------------------------------------------------------
--
Edit this bug report at http://bugs.php.net/?id=47204&edit=1