Request headers increased per call at client #10
Description
Test case:
$jsonRpc = new \Zend\Json\Server\Client('http://server-url.com');
for ($i = 0; $i < 25000; $i++) {
$jsonRpc->call('someMethod');
}
The method called in the server is a method that only returns hard-coded information, to avoid interferences.
Measuring the time the function spends proves that the time spent in the function gets increased at each request. After 20000+, the time spent by the call lasted more than 2.5 seconds.
I was able to isolate the issue to the merging of headers: in every request done the headers lasted more to be merged. After some analysis, I found out that he internal number of headers were being increased by two at every request.
The code that lead to this is: https://github.com/zendframework/zend-json-server/blob/master/src/Client.php#L121
$headers = $httpRequest->getHeaders();
$headers->addHeaders([
'Content-Type' => 'application/json',
'Accept' => 'application/json',
]);
if (! $headers->get('User-Agent')) {
$headers->addHeaderLine('User-Agent', 'Zend_Json_Server_Client');
}
The headers are added independently of their existence. User-Agent is at least checking its existence before being added, so the solution would be to do the same with "Content-Type" and "Accept".