Package home | Report new bug | New search | Development Roadmap Status: Open | Feedback | All | Closed Since Version 2.6.0

Bug #15937 Expect header sent for some versions of curl by default can not be unsetted
Submitted: 2009-02-24 19:30 UTC
From: kase Assigned: avb
Status: Closed Package: HTTP_Request2
PHP Version: 5.2.0 OS:
Roadmaps: 0.4.0    
Subscription  
Comments Add Comment Add patch


Anyone can comment on a bug. Have a simpler test case? Does it work for you on a different platform? Let us know! Just going to say 'Me too!'? Don't clutter the database with that please !
Your email address:
MUST BE VALID
Solve the problem : 21 + 3 = ?

 
 [2009-02-24 19:30 UTC] kase (Timo Gmell)
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

Comments

 [2009-03-02 03:35 UTC] doconnor (Daniel O'Connor)
Would this affect any of the other drivers?
 [2009-03-02 14:49 UTC] kase (Timo Gmell)
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-18 20:39 UTC] avb (Alexey Borzov)
-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-04-04 02:45 UTC] avb (Alexey Borzov)
-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.