PEAR is archived and read-only

This mirror preserves historical PEAR package releases and metadata so existing references remain available.

Home » Web Services » SOAP » Bug #5852

HTTP Transport to use curl when available, fixes double headers when NTLM auth

Details

Submitted2005-11-02 15:36 UTC
Frommartin at malditainternet dot com
Assignedyunosh
StatusWont fix
PackageSOAP
PHP Version4.4.0
OSlinux
Roadmaps(Not assigned)

Comments

[2005-11-02 15:36 UTC] martin at malditainternet dot com

Description:
------------
There's a curl-php 'feature' that will return the received headers for all requests done with just one curl_exec call on the same string.

Ie, if you make a request that request with NTLM authentication, CURL will do 2 requests: for the first one, it will receive a HTTP 401 with some negotiation/challenge headers and then, it sends another request with the auth data and gets a HTTP 200 response.

Then it returns the headers from the curl_exec functions:

HTTP/1.1 401 Unauthorized
blablabla

HTTP/1.1 200 OK
blabla

<html>
...

My patch just skips all the first headers and returns the last one, which is the most important (AFAIK)

Test script:
---------------
--- /tmp/SOAP-0.9.1/Transport/HTTP.php 2005-05-30 19:06:40.000000000 -0300
+++ SOAP/Transport/HTTP.php 2005-11-02 12:22:31.000000000 -0300
@@ -485,6 +485,10 @@
*/
function &_sendHTTP(&$msg, $options)
{
+ if (extension_loaded("curl"))
+ {
+ return $this->_sendHTTPS($msg,$options);
+ }
$this->incoming_payload = '';
$this->_getRequest($msg, $options);
$host = $this->urlparts['host'];
@@ -582,7 +586,8 @@
curl_setopt($ch, CURLOPT_FAILONERROR, 0);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
- curl_setopt($ch, CURLOPT_HEADER, 1);
+ curl_setopt($ch, CURLOPT_HEADER, 0);
+ curl_setopt($ch, CURLOPT_HEADERFUNCTION, '_SOAP_curl_parse_header');
if (defined('CURLOPT_HTTP_VERSION')) {
curl_setopt($ch, CURLOPT_HTTP_VERSION, 1);
}
@@ -599,6 +604,7 @@
$this->outgoing_payload = $msg;

$this->incoming_payload = curl_exec($ch);
+ $this->incoming_payload = _SOAP_curl_get_headers($ch) . $this->incoming_payload;
if (!$this->incoming_payload) {
$m = 'curl_exec error ' . curl_errno($ch) . ' ' . curl_error($ch);
curl_close($ch);
@@ -614,3 +620,38 @@
}

}
+/**
+ * Gets the last response HTTP header of a curl request (duplicated headers are generated when curl finds a redirection)
+ *
+ * This function will be used by curl itself
+ *
+ * @param object $ch curl object
+ * @param string $header header line received from the server
+ * @return int number of bytes processed
+ *
+ * @see curl_init()
+ */
+function _SOAP_curl_parse_header($ch,$header)
+{
+ global $_SOAP_CURL_HEADERS;
+ if (substr($_SOAP_CURL_HEADERS,-4) == "\r\n\r\n"){ // the variable has a full http header set, but we're receiving more headers. We'll discard those old headers and start with a new set.
+ $_SOAP_CURL_HEADERS='';
+ }
+ $_SOAP_CURL_HEADERS.=$header;
+ return strlen($header);
+}
+
+/**
+ * Returns the response HTTP headers for the last curl request
+ *
+ * @param object $ch curl object
+ * @return string headers received, including the last empty line
+ *
+ */
+function _SOAP_curl_get_headers($ch)
+{
+ // this global variable should be changed for something better, 'thread-safe'
+ return $GLOBALS['_SOAP_CURL_HEADERS'];
+}
+$GLOBALS['_SOAP_CURL_HEADERS']='';
+?>

[2005-11-02 15:36 UTC] martin at malditainternet dot com

sorry, wrong summary

[2005-11-02 18:48 UTC] martin at malditainternet dot com

Sorry, I forgot to add that this patch makes the HTTP Transport to use CURL when available (using the existing code for HTTPS requests)