#44584 [NEW]: CURLOPT_NOBODY sets request method to HEAD
| From: | humbads at alum dot mit dot edu | Date: | Mon, 31 Mar 2008 16:06:24 +0000 |
| Subject: | #44584 [NEW]: CURLOPT_NOBODY sets request method to HEAD | ||
| Groups: | php.doc.bugs | ||
| Request: | Send a blank email to doc-bugs+get-644@lists.php.net to get a copy of this message | ||
From: humbads at alum dot mit dot edu
Operating system: all
PHP version: Irrelevant
PHP Bug Type: Documentation problem
Bug description: CURLOPT_NOBODY sets request method to HEAD
Description:
------------
Setting CURLOPT_NOBODY to "true" with curl_setopt sets the request method
to HEAD for HTTP(s) requests, and furthermore, cURL does not read any
content even if a Content-Length header is found in the headers. However,
setting CURLOPT_NOBODY back to "false" does *not* reset the request method
back to GET. But because it is now "false", cURL will wait for content if
the response contains a content-length header.
If CURLOPT_NOBODY is set to "true" and back to "false", curl_exec will
appear to hang unexpectedly for a request. If the server times out the
connection, then an curl will return an error like "transfer closed with
2523 bytes remaining to read".
From a usability standpoint, setting CURLOPT_NOBODY to "true" should NOT
set the request method to HEAD if it is not going to reset it back when it
is set to "false". Otherwise, the parameter is not truly "on/off", and has
unknown, undocumented side-effects. Ideally, CURLOPT_NOBODY should only
cause cURL to ignore the content-length headers and not read any content.
The only way to reset the state of the cURL session is to set
CURLOPT_HTTPGET to "true", which both sets the request method to GET and
causes cURL to read content.
This behavior is not mentioned the PHP documentation, so it would be nice
to add something about it. Otherwise, reusing a curl handle causes
unexpected behavior. PHP bug 40997 is a consequence of this behavior:
http://bugs.php.net/bug.php?id=40997
So there are two documentation requests:
1. Mention that setting CURLOPT_NOBODY to "true" sets the request method
to HEAD for HTTP(S) requests, and cURL ignores the content-length header.
2. Mention that setting CURLOPT_NOBODY to "false" causes cURL to wait for
content if a content-length header is read, but it does *not* reset the
request method back to GET.
Reproduce code:
---------------
$ch = curl_init();
curl_setopt($ch, CURLOPT_TIMEOUT, 3); // set execution timeout
curl_setopt($ch, CURLOPT_URL,
"http://static.php.net/www.php.net/images/php.gif");
// Changes request method to HEAD and ignore content
curl_setopt($ch, CURLOPT_NOBODY, true);
// cURL will wait for content, but not change the request method.
// curl_exec will timeout waiting for the content
curl_setopt($ch, CURLOPT_NOBODY, false);
// Setting HTTPGET to true resets the request method back to GET
// and cURL will read content.
//curl_setopt($ch, CURLOPT_HTTPGET, true);
var_dump(curl_exec($ch));
print curl_error($ch)."\n";
curl_close($ch);
--
Edit bug report at http://bugs.php.net/?id=44584&edit=1
--
Try a CVS snapshot (PHP 5.2): http://bugs.php.net/fix.php?id=44584&r=trysnapshot52
Try a CVS snapshot (PHP 5.3): http://bugs.php.net/fix.php?id=44584&r=trysnapshot53
Try a CVS snapshot (PHP 6.0): http://bugs.php.net/fix.php?id=44584&r=trysnapshot60
Fixed in CVS: http://bugs.php.net/fix.php?id=44584&r=fixedcvs
Fixed in release: http://bugs.php.net/fix.php?id=44584&r=alreadyfixed
Need backtrace: http://bugs.php.net/fix.php?id=44584&r=needtrace
Need Reproduce Script: http://bugs.php.net/fix.php?id=44584&r=needscript
Try newer version: http://bugs.php.net/fix.php?id=44584&r=oldversion
Not developer issue: http://bugs.php.net/fix.php?id=44584&r=support
Expected behavior: http://bugs.php.net/fix.php?id=44584&r=notwrong
Not enough info: http://bugs.php.net/fix.php?id=44584&r=notenoughinfo
Submitted twice: http://bugs.php.net/fix.php?id=44584&r=submittedtwice
register_globals: http://bugs.php.net/fix.php?id=44584&r=globals
PHP 4 support discontinued: http://bugs.php.net/fix.php?id=44584&r=php4
Daylight Savings: http://bugs.php.net/fix.php?id=44584&r=dst
IIS Stability: http://bugs.php.net/fix.php?id=44584&r=isapi
Install GNU Sed: http://bugs.php.net/fix.php?id=44584&r=gnused
Floating point limitations: http://bugs.php.net/fix.php?id=44584&r=float
No Zend Extensions: http://bugs.php.net/fix.php?id=44584&r=nozend
MySQL Configuration Error: http://bugs.php.net/fix.php?id=44584&r=mysqlcfg