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

Bug #15716 fatal php error if requested server sends no headers (curl-adapter)
Submitted: 2009-01-22 09:34 UTC
From: kase Assigned: avb
Status: Closed Package: HTTP_Request2 (version 0.2.0)
PHP Version: 5.2.8 OS:
Roadmaps: 0.3.0    
Subscription  


 [2009-01-22 09:34 UTC] kase (Timo Gmell)
Description: ------------ Hi again :), if the requested server sends no headers, callbackWriteHeader is not called by curl. Curl only calls the callbackWriteBody function, that tries to append the body to $this->response, but this var is still null. Sorry, I can not provide an address to a (stupid) http server, that sends no headers, but you can reproduce this bug easily by connecting to a ssh server. Thanks! Test script: --------------- $url = new Net_URL2('http://www.domain-with-ssh-server-running.com:port-of-ssh-server'); $request = new HTTP_Request2($url); $request->setAdapter('Curl'); $request->send(); Expected result: ---------------- send() returns a valid response, containing the received body. For the example above: SSH-2.0-OpenSSH_4.3p2 Debian-9etch3 Actual result: -------------- Fatal error: Call to a member function appendBody() on a non-object in pear/HTTP/Request2/Adapter/Curl.php on line 342

Comments

 [2009-01-22 09:48 UTC] avb (Alexey Borzov)
send() won't be able to return a valid response, since response without HTTP status line is obviously invalid in context of HTTP. Anyway, Fatal error should not happen here, I'll change Curl adapter to throw an Exception in this case.
 [2009-01-22 10:03 UTC] kase (Timo Gmell)
Hi, If you use "plain" curl, the response is returned and the status code is set to 0. Maybe this fix is OK for you? (it does not break anything) Curl.php 241: ++ if (empty($this->response)) { $this->response = new HTTP_Request2_Response('HTTP/1.0 000 Malformed Response', false); } Behavior of curl (same as with the fix above): $ch = curl_init('http://www.domain.com:22'); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); print_r(curl_getinfo($ch)); $response = curl_exec($ch); print_r($response); ---------------- Array ( [url] => http://www.domain.com:22 [http_code] => 0 [header_size] => 0 [request_size] => 0 [filetime] => 0 [ssl_verify_result] => 0 [redirect_count] => 0 [total_time] => 0 [namelookup_time] => 0 [connect_time] => 0 [pretransfer_time] => 0 [size_upload] => 0 [size_download] => 0 [speed_download] => 0 [speed_upload] => 0 [download_content_length] => 0 [upload_content_length] => 0 [starttransfer_time] => 0 [redirect_time] => 0 ) SSH-2.0-OpenSSH_4.3p2 Debian-9etch3
 [2009-01-22 10:16 UTC] kase (Timo Gmell)
Sorry, i have swapped some lines in the curl example: $ch = curl_init('http://www.domain.com:22'); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); $response = curl_exec($ch); print_r(curl_getinfo($ch)); print_r($response); ----- Array ( [url] => http://www.domain.com:22 [http_code] => 0 [header_size] => 0 [request_size] => 56 [filetime] => -1 [ssl_verify_result] => 0 [redirect_count] => 0 [total_time] => 0.122447 [namelookup_time] => 2.0E-5 [connect_time] => 0.049861 [pretransfer_time] => 0.049864 [size_upload] => 0 [size_download] => 36 [speed_download] => 294 [speed_upload] => 0 [download_content_length] => 0 [upload_content_length] => 0 [starttransfer_time] => 0.121758 [redirect_time] => 0 ) SSH-2.0-OpenSSH_4.3p2 Debian-9etch3
 [2009-01-22 14:44 UTC] avb (Alexey Borzov)
To make both Socket and Curl adapters behave the same way I'll need either to make Curl one throw an exception, or add some special handling of non-HTTP responses to Socket one. Throwing an exception in Curl is much easier.
 [2009-01-22 15:38 UTC] kase (Timo Gmell)
Ok. Adding an exception works for me, too. If anyone needs the behavior of curl, maybe he can add a new feature request to this package. Thanks!
 [2009-01-22 23:21 UTC] avb (Alexey Borzov)
This bug has been fixed in CVS. If this was a documentation problem, the fix will appear on pear.php.net by the end of next Sunday (CET). If this was a problem with the pear.php.net website, the change should be live shortly. Otherwise, the fix will appear in the package's next release. Thank you for the report and for helping us make PEAR better.