From 9decb91e487db7cf575f6a4cbdd43afba7ea1cac Mon Sep 17 00:00:00 2001 From: ggiunta Date: Sat, 5 Sep 2009 15:27:47 +0000 Subject: [PATCH] added new method SetUserAgent to client to allow having different user-agent http headers git-svn-id: https://svn.code.sf.net/p/phpxmlrpc/code/trunk/xmlrpc@56 013ecfd8-0664-425d-a759-9c98391dc3f9 --- ChangeLog | 3 +++ lib/xmlrpc.inc | 42 +++++++++++++++++++++++++++++------------- 2 files changed, 32 insertions(+), 13 deletions(-) diff --git a/ChangeLog b/ChangeLog index c8a5050..10348b0 100644 --- a/ChangeLog +++ b/ChangeLog @@ -10,6 +10,9 @@ * server.php, testsuite.php: add a new test and server method for exception catching in the server + * xmlrpc.inc: added new method SetUserAgent to client to allow having different + user-agent http headers + 2009-08-05 - G. Giunta (giunta.gaetano@gmail.com) * xmlrpc_wrappers.inc: improve compatibility with php 5.0 when registering diff --git a/lib/xmlrpc.inc b/lib/xmlrpc.inc index 74c2c25..52424b0 100644 --- a/lib/xmlrpc.inc +++ b/lib/xmlrpc.inc @@ -828,7 +828,7 @@ var $proxy_pass=''; var $proxy_authtype=1; var $cookies=array(); - var $extracurlopts=array(); + var $extracurlopts=array(); /** * List of http compression methods accepted by the client for responses. @@ -861,6 +861,10 @@ * valid strings are 'xmlrpcvals', 'phpvals' or 'xml' */ var $return_type = 'xmlrpcvals'; + /** + * Sent to servers in http headers + */ + var $user_agent; /** * @param string $path either the complete server URL or the PATH part of the xmlrc server URL, e.g. /xmlrpc/server.php @@ -933,6 +937,9 @@ // by default the xml parser can support these 3 charset encodings $this->accepted_charset_encodings = array('UTF-8', 'ISO-8859-1', 'US-ASCII'); + + // initialize user_agent string + $this->user_agent = $GLOBALS['xmlrpcName'] . ' ' . $GLOBALS['xmlrpcVersion']; } /** @@ -1099,15 +1106,24 @@ } } - /** - * Directly set cURL options, for extra flexibility - * It allows eg. to bind client to a specific IP interface / address - * @param $options array - */ - function SetCurlOptions( $options ) - { - $this->extracurlopts = $options; - } + /** + * Directly set cURL options, for extra flexibility + * It allows eg. to bind client to a specific IP interface / address + * @param $options array + */ + function SetCurlOptions( $options ) + { + $this->extracurlopts = $options; + } + + /** + * Set user-agent string that will be used by this client instance + * in http headers sent to the server + */ + function SetUserAgent( $agentstring ) + { + $this->user_agent = $agentstring; + } /** * Send an xmlrpc request @@ -1327,7 +1343,7 @@ } $op= 'POST ' . $uri. " HTTP/1.0\r\n" . - 'User-Agent: ' . $GLOBALS['xmlrpcName'] . ' ' . $GLOBALS['xmlrpcVersion'] . "\r\n" . + 'User-Agent: ' . $this->user_agent . "\r\n" . 'Host: '. $server . ':' . $port . "\r\n" . $credentials . $proxy_credentials . @@ -1510,7 +1526,7 @@ { curl_setopt($curl, CURLOPT_VERBOSE, 1); } - curl_setopt($curl, CURLOPT_USERAGENT, $GLOBALS['xmlrpcName'].' '.$GLOBALS['xmlrpcVersion']); + curl_setopt($curl, CURLOPT_USERAGENT, $this->user_agent); // required for XMLRPC: post the data curl_setopt($curl, CURLOPT_POST, 1); // the data @@ -3449,7 +3465,7 @@ xmlrpc_encode_entitites($this->errstr, $GLOBALS['xmlrpc_internalencoding'], $cha else { $arr = array(); - reset($php_val); + reset($php_val); while(list($k,$v) = each($php_val)) { $arr[$k] = php_xmlrpc_encode($v, $options); -- 2.43.0