added new method SetUserAgent to client to allow having different user-agent http...
authorggiunta <ggiunta@013ecfd8-0664-425d-a759-9c98391dc3f9>
Sat, 5 Sep 2009 15:27:47 +0000 (15:27 +0000)
committerggiunta <ggiunta@013ecfd8-0664-425d-a759-9c98391dc3f9>
Sat, 5 Sep 2009 15:27:47 +0000 (15:27 +0000)
git-svn-id: https://svn.code.sf.net/p/phpxmlrpc/code/trunk/xmlrpc@56 013ecfd8-0664-425d-a759-9c98391dc3f9

ChangeLog
lib/xmlrpc.inc

index c8a5050..10348b0 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -10,6 +10,9 @@
        * server.php, testsuite.php: add a new test and server method for exception\r
        catching in the server\r
 \r
+       * xmlrpc.inc: added new method SetUserAgent to client to allow having different\r
+       user-agent http headers\r
+\r
 2009-08-05 - G. Giunta (giunta.gaetano@gmail.com)\r
 \r
        * xmlrpc_wrappers.inc: improve compatibility with php 5.0 when registering\r
index 74c2c25..52424b0 100644 (file)
                var $proxy_pass='';\r
                var $proxy_authtype=1;\r
                var $cookies=array();\r
-           var $extracurlopts=array();\r
+               var $extracurlopts=array();\r
 \r
                /**\r
                * List of http compression methods accepted by the client for responses.\r
                * valid strings are 'xmlrpcvals', 'phpvals' or 'xml'\r
                */\r
                var $return_type = 'xmlrpcvals';\r
+               /**\r
+               * Sent to servers in http headers\r
+               */\r
+               var $user_agent;\r
 \r
                /**\r
                * @param string $path either the complete server URL or the PATH part of the xmlrc server URL, e.g. /xmlrpc/server.php\r
 \r
                        // by default the xml parser can support these 3 charset encodings\r
                        $this->accepted_charset_encodings = array('UTF-8', 'ISO-8859-1', 'US-ASCII');\r
+\r
+                       // initialize user_agent string\r
+                       $this->user_agent = $GLOBALS['xmlrpcName'] . ' ' . $GLOBALS['xmlrpcVersion'];\r
                }\r
 \r
                /**\r
                        }\r
                }\r
 \r
-           /**\r
-           * Directly set cURL options, for extra flexibility\r
-           * It allows eg. to bind client to a specific IP interface / address\r
-           * @param $options array\r
-           */\r
-           function SetCurlOptions( $options )\r
-           {\r
-               $this->extracurlopts = $options;\r
-           }\r
+               /**\r
+               * Directly set cURL options, for extra flexibility\r
+               * It allows eg. to bind client to a specific IP interface / address\r
+               * @param $options array\r
+               */\r
+               function SetCurlOptions( $options )\r
+               {\r
+                       $this->extracurlopts = $options;\r
+               }\r
+\r
+               /**\r
+               * Set user-agent string that will be used by this client instance\r
+               * in http headers sent to the server\r
+               */\r
+               function SetUserAgent( $agentstring )\r
+               {\r
+                       $this->user_agent = $agentstring;\r
+               }\r
 \r
                /**\r
                * Send an xmlrpc request\r
                        }\r
 \r
                        $op= 'POST ' . $uri. " HTTP/1.0\r\n" .\r
-                               'User-Agent: ' . $GLOBALS['xmlrpcName'] . ' ' . $GLOBALS['xmlrpcVersion'] . "\r\n" .\r
+                               'User-Agent: ' . $this->user_agent . "\r\n" .\r
                                'Host: '. $server . ':' . $port . "\r\n" .\r
                                $credentials .\r
                                $proxy_credentials .\r
                        {\r
                                curl_setopt($curl, CURLOPT_VERBOSE, 1);\r
                        }\r
-                       curl_setopt($curl, CURLOPT_USERAGENT, $GLOBALS['xmlrpcName'].' '.$GLOBALS['xmlrpcVersion']);\r
+                       curl_setopt($curl, CURLOPT_USERAGENT, $this->user_agent);\r
                        // required for XMLRPC: post the data\r
                        curl_setopt($curl, CURLOPT_POST, 1);\r
                        // the data\r
@@ -3449,7 +3465,7 @@ xmlrpc_encode_entitites($this->errstr, $GLOBALS['xmlrpc_internalencoding'], $cha
                                else\r
                                {\r
                                        $arr = array();\r
-                                   reset($php_val);\r
+                                       reset($php_val);\r
                                        while(list($k,$v) = each($php_val))\r
                                        {\r
                                                $arr[$k] = php_xmlrpc_encode($v, $options);\r