Bug #15937 [Ana->Csd]: Expect header sent for some versions of curl by default can not be unsetted
| From: | borz_off at cs dot msu dot su | Date: | Fri, 03 Apr 2009 21:45:19 +0000 |
| Subject: | Bug #15937 [Ana->Csd]: Expect header sent for some versions of curl by default can not be unsetted | ||
| References: | 1 | Groups: | php.pear.bugs |
| Request: | Send a blank email to pear-bugs+get-302@lists.php.net to get a copy of this message | ||
Edit report at http://pear.php.net/bugs/bug.php?id=15937&edit=1
ID: 15937
Updated by: borz_off@cs.msu.su
Reported By: kase at gmx dot net
Summary: Expect header sent for some versions of curl by
default can not be unsetted
-Status: Analyzed
+Status: Closed
Type: Bug
Package: HTTP_Request2
PHP Version: 5.2.0
-Assigned To:
+Assigned To: avb
Roadmap Versions:
New Comment:
-Status: Analyzed
+Status: Closed
-Assigned To:
+Assigned To: avb
Fixed in CVS: setHeader() now works as was advertised from the very
beginning, which means
$request->setHeader('Expect', '');
// or
$request->setHeader('Expect:');
will add an 'Expect:' header to request, while
$request->setHeader('Expect, null);
// or
$request->setHeader('Expect');
will remove 'Expect' header from request.
Previous Comments:
------------------------------------------------------------------------
[2009-03-18 16:39:52] avb
-Status: Open
+Status: Analyzed
Looks like we'll have to differentiate between
$request->setHeader('Expect', '');
and
$request->setHeader('Expect');
the former will send empty 'Expect: ' header, while the latter will
remove header from the array as it does now.
------------------------------------------------------------------------
[2009-03-02 09:49:53] kase
Hi Daniel,
sending an empty header value seems to work for all webservers i have
tested, but i am not sure if it is RFC compliant.
I think there are 4 ways to fix this bug:
1: The adapter should decide what to do with an empty header value. The
curl adapter can set the empty value to unset it and the socket adapter
can unset it directly, ...
2 (if it is RFC compliant):
Request2.php line 458
if (!$value) {
- unset($this->headers[$name]);
+ $this->headers[$name] = '';
}
3:
Curl.php line 261
if (!isset($headers['accept-encoding'])) {
$headers['accept-encoding'] = '';
}
+ // always unset expect header if it is not set
+ if (!isset($headers['expect'])) {
+ $headers['expect'] = '';
+ }
// set headers having special cURL keys
4:
add an option to configure the expect behavior for all adapters
I am using 3) as a workaround atm and it seems to work for all requests
(for me).
Thanks
------------------------------------------------------------------------
[2009-03-01 22:35:09] doconnor
Would this affect any of the other drivers?
------------------------------------------------------------------------
[2009-02-24 14:30:38] kase
Description:
------------
Hi Alexey,
some versions of curl send the Expect header for a post request by
default. Some webservers (e.g. Lighttpd) can not handle this header and
send a "417 Expectation Failed" back.
To disable the default expect header, you have to set it to an empty
string. (see *1 and *2).
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Expect:'));
This is not possible at the moment with the Request2 package, because
if you set $request->setHeader('Expect', '') it will be unset from the
headers array, so curl sends the header again by default.
Can you implement an option to configure the expect header for
curl-adapter, or allow setting an empty header to the setHeader
function?
*1:
http://www.shoemoney.com/2008/12/29/lib-curl-twitter-api-expect-100-continue-pain-and-how-to-fix-it/
*2: http://redmine.lighttpd.net/issues/1017#note-17
Thanks!
Test script:
---------------
For a curl version sending NO expect header by default (to reproduce)
$request = new HttpRequest('http://sourceforge.net/');
$request->setHeader('Expect', '100-Continue');
$request->setMethod('POST');
$request->addPostParameter('a', 'b');
$response = $request->send();
print_r($response->getStatus());
Fix for a curl version (e.g. 7.15.*, debian etch) sending expect header
by default
$request = new HttpRequest('http://sourceforge.net/');
$request->setHeader('Expect', '');
$request->setMethod('POST');
$request->addPostParameter('a', 'b');
$response = $request->send();
print_r($response->getStatus());
Expected result:
----------------
417
200
Actual result:
--------------
417
417
------------------------------------------------------------------------
--
Edit this bug report at http://pear.php.net/bugs/bug.php?id=15937&edit=1