Trying to override the headers of Laminas XML-RPC server response. The header Content-Type should be application/xml instead of the default text/html. Having read the docs it isn’t clear what to do, it states:
Similar to request objects,
Laminas\XmlRpc\Servercan return custom response objects; by default, aLaminas\XmlRpc\Response\Httpobject is returned, which sends an appropriateContent-TypeHTTP header for use with XML-RPC. Possible uses of a custom object would be to log responses, or to send responses back toSTDOUT.
To use a custom response class, use
Laminas\XmlRpc\Server::setResponseClass()prior to callinghandle().
There is a example usage of setResponseClass() but not what the class should look like. The only thing that is clear from looking at the source is that it should extend Laminas\XmlRpc\Response and that’s it.
What I have tried but isn’t working:
use Laminas\XmlRpc\Response as XmlRpcResponse;
/**
* HTTP response
*/
class XmlRpcService extends XmlRpcResponse
{
protected $type = 'application/xml'; // This was just for testing but isn't working either
/**
* Override __toString() to send HTTP Content-Type header
*
* @return string
*/
public function __toString()
{
if (! headers_sent()) {
header('Content-Type: application/xml; charset=' . strtolower($this->getEncoding()));
}
return parent::__toString();
}
}
$server = new \Laminas\XmlRpc\Server();
$server->setClass( 'SomeClass', 'namespace' );
$server->setResponseClass( XmlRpcService::class);
return $server->handle();
Hope some one can point me in the right direction of how to override the headers.