ZF-3288: Custom User-Agent support in Zend_XmlRpc_Client requests

Issue Type: Improvement Created: 2008-05-18T23:48:37.000+0000 Last Updated: 2009-08-22T08:54:14.000+0000 Status: Resolved Fix version(s): - 1.10.0 (27/Jan/10)

Reporter: MIkayel Sukiasyan (micbox) Assignee: Lars Strojny (lars) Tags: - Zend_XmlRpc_Client

Related issues: Attachments: - zend_xmlrpc_client-user_agent.diff


IT IS IMPOSSIBLE TO SET A CUSTOM User-Agent HTTP header with Zend_XmlRpc_Client !!!

According to the HTTP specification, the User-Agent field may contain mulitple product tokens and comments identifying the client. By convention, the product tokens are listed in the order of their significance for identifying the application. The token must be organized as follows "User-Agent: Agent-name/Protocol version/Client version".

It is a very important feature to be incorporated into Zend_XmlRpc_Client class in order to reach proper client identification for XML-RPC services.

I propose a VERY simple change in Zend_XmlRpc_Client class. The only method concerned is doRequest(). Just an extra optional $userAgent param is added. Everything else remains the same.

Below is the changed source code:

<pre class="highlight">
     * Perform an XML-RPC request and return a response.
     * @param Zend_XmlRpc_Request $request
     * @param null|Zend_XmlRpc_Response $response
     * @param string $userAgent
     * @return void
    public function doRequest($request, $response = null, $userAgent = 'Zend_XmlRpc_Client')
        $this->_lastRequest = $request;

        iconv_set_encoding('input_encoding', 'UTF-8');
        iconv_set_encoding('output_encoding', 'UTF-8');
        iconv_set_encoding('internal_encoding', 'UTF-8');

        $http = $this->getHttpClient();

            'Content-Type: text/xml; charset=utf-8',
            "User-Agent: $userAgent" // HERE IS THE CHANGE added by Mikayel Sukiasyan (userAgent param)
            //'User-Agent: Zend_XmlRpc_Client' // HERE IS THE PREVIOUS CODE

        $xml = $this->_lastRequest->__toString();
        $httpResponse = $http->request(Zend_Http_Client::POST);

        if (! $httpResponse->isSuccessful()) {
            throw new Zend_XmlRpc_Client_HttpException(

        if ($response === null) {
            $response = new Zend_XmlRpc_Response();
        $this->_lastResponse = $response;


Posted by Matthew Weier O'Phinney (matthew) on 2008-05-27T05:49:37.000+0000

Changing to Feature Request and downgrading priority to Minor. The user agent string is already present, so there are no violations of the HTTP spec. The request is to be able to modify the user agent. I do not think using the patch makes sense; instead, it should be done via accessors:

<pre class="highlight">
public function setUserAgent($userAgent)

public function getUserAgent()

Scheduling for next minor release.

Posted by Matthew Weier O'Phinney (matthew) on 2008-09-05T10:34:11.000+0000

Satoru -- please do not work on this issue. There are some good reasons for some of the variables to be private, and I will work with the maintainer, Mike Naberezny, to address the issues reported.

Posted by old of Satoru Yoshida ( on 2008-09-05T21:09:34.000+0000

Hi Matthew. I see. But the issue you say about variables may be ZF-3415. I will reopen ZF-3415 for you.

Posted by Lars Strojny (lars) on 2009-08-22T08:54:11.000+0000

It's now possible to set a custom UA: either set a custom HTTP client object with your custom user agent or do getHttpClient() and set it accordingly. Fixed in r17752

Have you found an issue?

See the Overview section for more details.


© 2006-2018 by Zend, a Rogue Wave Company. Made with by awesome contributors.

This website is built using zend-expressive and it runs on PHP 7.