cvs: pear /XML_RPC RPC.php package.xml package2.xml

From: Date: Wed, 06 Apr 2005 23:49:15 +0000
Subject: cvs: pear /XML_RPC RPC.php package.xml package2.xml
Groups: php.pear.cvs 
Request: Send a blank email to pear-cvs+get-31004@lists.php.net to get a copy of this message
danielc Wed Apr 6 19:49:15 2005 EDT Modified files: /pear/XML_RPC RPC.php package.xml package2.xml Log: * Add createHeaders() method and $headers property to XML_RPC_Client to make testing easier. http://cvs.php.net/diff.php/pear/XML_RPC/RPC.php?r1=1.65&r2=1.66&ty=u Index: pear/XML_RPC/RPC.php diff -u pear/XML_RPC/RPC.php:1.65 pear/XML_RPC/RPC.php:1.66 --- pear/XML_RPC/RPC.php:1.65 Wed Apr 6 12:35:49 2005 +++ pear/XML_RPC/RPC.php Wed Apr 6 19:49:15 2005 @@ -32,7 +32,7 @@ * @author Martin Jansen <mj@php.net> * @author Daniel Convissor <danielc@php.net> * @copyright 1999-2001 Edd Dumbill - * @version CVS: $Id: RPC.php,v 1.65 2005/04/06 16:35:49 danielc Exp $ + * @version CVS: $Id: RPC.php,v 1.66 2005/04/06 23:49:15 danielc Exp $ * @link http://pear.php.net/package/XML_RPC */ @@ -585,6 +585,12 @@ */ var $debug = 0; + /** + * The HTTP headers for the current request. + * @var string + */ + var $headers = ''; + /** * Sets the object's properties @@ -744,6 +750,7 @@ * @return object an XML_RPC_Response object. 0 is returned if any * problems happen. * + * @access protected * @see XML_RPC_Client::send() */ function sendPayloadHTTP10($msg, $server, $port, $timeout = 0, @@ -803,39 +810,19 @@ stream_set_timeout($fp, $timeout); } + // Pre-emptive BC hacks for fools calling sendPayloadHTTP10() directly + if ($username != $this->username) { + $this->setCredentials($username, $password); + } + // Only create the payload if it was not created previously if (empty($msg->payload)) { $msg->createPayload(); } + $this->createHeaders($msg); - // thanks to Grant Rauscher <grant7@firstworld.net> for this - $credentials = ''; - if ($username != '') { - $credentials = 'Authorization: Basic ' . - base64_encode($username . ':' . $password) . "\r\n"; - } - - if ($this->proxy) { - $op = 'POST ' . $this->protocol . $server; - if ($this->proxy_port) { - $op .= ':' . $this->port; - } - } else { - $op = 'POST '; - } - - $op .= $this->path. " HTTP/1.0\r\n" . - "User-Agent: PEAR XML_RPC\r\n" . - 'Host: ' . $server . "\r\n"; - if ($this->proxy && $this->proxy_user != '') { - $op .= 'Proxy-Authorization: Basic ' . - base64_encode($this->proxy_user . ':' . $this->proxy_pass) . - "\r\n"; - } - $op .= $credentials . - "Content-Type: text/xml\r\n" . - 'Content-Length: ' . strlen($msg->payload) . "\r\n\r\n" . - $msg->payload; + $op = $this->headers . "\r\n\r\n"; + $op .= $msg->payload; if (!fputs($fp, $op, strlen($op))) { $this->errstr = 'Write error'; @@ -854,6 +841,51 @@ fclose($fp); return $resp; } + + /** + * Determines the HTTP headers and puts it in the $headers property + * + * @param object $msg the XML_RPC_Message object + * + * @return boolean TRUE if okay, FALSE if the message payload isn't set. + * + * @access protected + */ + function createHeaders($msg) + { + if (empty($msg->payload)) { + return false; + } + if ($this->proxy) { + $this->headers = 'POST ' . $this->protocol . $this->server; + if ($this->proxy_port) { + $this->headers .= ':' . $this->port; + } + } else { + $this->headers = 'POST '; + } + $this->headers .= $this->path. " HTTP/1.0\r\n"; + + $this->headers .= "User-Agent: PEAR XML_RPC\r\n"; + $this->headers .= 'Host: ' . $this->server . "\r\n"; + + if ($this->proxy && $this->proxy_user) { + $this->headers .= 'Proxy-Authorization: Basic ' + . base64_encode("$this->proxy_user:$this->proxy_pass") + . "\r\n"; + } + + // thanks to Grant Rauscher <grant7@firstworld.net> for this + if ($this->username) { + $this->headers .= 'Authorization: Basic ' + . base64_encode("$this->username:$this->password") + . "\r\n"; + } + + $this->headers .= "Content-Type: text/xml\r\n"; + $this->headers .= 'Content-Length: ' . strlen($msg->payload); + return true; + } } /** http://cvs.php.net/diff.php/pear/XML_RPC/package.xml?r1=1.46&r2=1.47&ty=u Index: pear/XML_RPC/package.xml diff -u pear/XML_RPC/package.xml:1.46 pear/XML_RPC/package.xml:1.47 --- pear/XML_RPC/package.xml:1.46 Wed Apr 6 18:53:25 2005 +++ pear/XML_RPC/package.xml Wed Apr 6 19:49:15 2005 @@ -2,7 +2,7 @@ <!DOCTYPE package SYSTEM "http://pear.php.net/dtd/package-1.0"> <package version="1.0"> - <!-- $Id: package.xml,v 1.46 2005/04/06 22:53:25 danielc Exp $ --> + <!-- $Id: package.xml,v 1.47 2005/04/06 23:49:15 danielc Exp $ --> <name>XML_RPC</name> <summary>PHP implementation of the XML-RPC protocol</summary> @@ -31,7 +31,7 @@ <release> <version>1.3.0RC1</version> - <date>2005-04-06</date> + <date>2005-04-07</date> <state>beta</state> <notes><![CDATA[ * Improve timeout handling for situations where connection to server is made but no response is not received in time. Accomplished via stream_set_timeout(). Request 3963. @@ -39,6 +39,7 @@ * Add the createServerPayload() and createServerHeaders() methods and the $server_payload and $server_headers properties. Request 3121. * As in earlier versions, if the $serviceNow parameter to XML_RPC_Server() is 0, no data will be returned, but now the new $server_payload and $server_headers properties will be set. * Convert the parser handle to an integer before using it as an index for $XML_RPC_xh[$parser]. Reduces E_STRICT notices. Bug 3782. +* Add createHeaders() method and $headers property to XML_RPC_Client to make testing easier. ]]></notes> <filelist> http://cvs.php.net/diff.php/pear/XML_RPC/package2.xml?r1=1.8&r2=1.9&ty=u Index: pear/XML_RPC/package2.xml diff -u pear/XML_RPC/package2.xml:1.8 pear/XML_RPC/package2.xml:1.9 --- pear/XML_RPC/package2.xml:1.8 Wed Apr 6 18:53:25 2005 +++ pear/XML_RPC/package2.xml Wed Apr 6 19:49:15 2005 @@ -8,7 +8,7 @@ http://pear.php.net/dtd/package-2.0 http://pear.php.net/dtd/package-2.0.xsd"> - <!-- $Id: package2.xml,v 1.8 2005/04/06 22:53:25 danielc Exp $ --> + <!-- $Id: package2.xml,v 1.9 2005/04/06 23:49:15 danielc Exp $ --> <name>XML_RPC</name> <channel>pear.php.net</channel> @@ -32,7 +32,7 @@ <active>yes</active> </lead> - <date>2005-04-06</date> + <date>2005-04-07</date> <version> <release>1.3.0RC1</release> @@ -50,6 +50,7 @@ * Add the createServerPayload() and createServerHeaders() methods and the $server_payload and $server_headers properties. Request 3121. * As in earlier versions, if the $serviceNow parameter to XML_RPC_Server() is 0, no data will be returned, but now the new $server_payload and $server_headers properties will be set. * Convert the parser handle to an integer before using it as an index for $XML_RPC_xh[$parser]. Reduces E_STRICT notices. Bug 3782. +* Add createHeaders() method and $headers property to XML_RPC_Client to make testing easier. ]]></notes> <contents>

« previous php.pear.cvs (#31004) next »