Skip to content
This repository was archived by the owner on Apr 28, 2020. It is now read-only.

Commit 0c28f13

Browse files
committed
Merge branch 'fix/#27-fix-memory-leak-in-header-creation-logic'
Close #27
2 parents c2cac5d + 6340916 commit 0c28f13

File tree

3 files changed

+73
-8
lines changed

3 files changed

+73
-8
lines changed

CHANGELOG.md

+21-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
All notable changes to this project will be documented in this file, in reverse chronological order by release.
44

5-
## 2.6.1 - TBD
5+
## 2.6.2 - TBD
66

77
### Added
88

@@ -20,6 +20,26 @@ All notable changes to this project will be documented in this file, in reverse
2020

2121
- Nothing.
2222

23+
## 2.6.1 - 2017-08-11
24+
25+
### Added
26+
27+
- Nothing.
28+
29+
### Deprecated
30+
31+
- Nothing.
32+
33+
### Removed
34+
35+
- Nothing.
36+
37+
### Fixed
38+
39+
- [#27](https://github.com/zendframework/zend-xmlrpc/pull/19) fixed a memory leak
40+
caused by repetitive addition of `Accept` and `Content-Type` headers on subsequent
41+
HTTP requests produced by the `Zend\XmlRpc\Client`.
42+
2343
## 2.6.0 - 2016-06-21
2444

2545
### Added

src/Client.php

+16-7
Original file line numberDiff line numberDiff line change
@@ -181,10 +181,15 @@ public function skipSystemLookup()
181181
/**
182182
* Perform an XML-RPC request and return a response.
183183
*
184-
* @param \Zend\XmlRpc\Request $request
184+
* @param \Zend\XmlRpc\Request $request
185185
* @param null|\Zend\XmlRpc\Response $response
186-
* @return void
186+
*
187+
* @throws \Zend\Http\Exception\InvalidArgumentException
188+
* @throws \Zend\Http\Client\Exception\RuntimeException
187189
* @throws \Zend\XmlRpc\Client\Exception\HttpException
190+
* @throws \Zend\XmlRpc\Exception\ValueException
191+
*
192+
* @return void
188193
*/
189194
public function doRequest($request, $response = null)
190195
{
@@ -205,12 +210,16 @@ public function doRequest($request, $response = null)
205210
}
206211

207212
$headers = $httpRequest->getHeaders();
208-
$headers->addHeaders([
209-
'Content-Type: text/xml; charset=utf-8',
210-
'Accept: text/xml',
211-
]);
212213

213-
if (!$headers->get('user-agent')) {
214+
if (!$headers->has('Content-Type')) {
215+
$headers->addHeaderLine('Content-Type', 'text/xml; charset=utf-8');
216+
}
217+
218+
if (!$headers->has('Accept')) {
219+
$headers->addHeaderLine('Accept', 'text/xml');
220+
}
221+
222+
if (!$headers->has('user-agent')) {
214223
$headers->addHeaderLine('user-agent', 'Zend_XmlRpc_Client');
215224
}
216225

test/ClientTest.php

+36
Original file line numberDiff line numberDiff line change
@@ -603,6 +603,42 @@ public function testCustomHttpClientUserAgentIsNotOverridden()
603603
$this->assertSame($expectedUserAgent, $this->httpClient->getHeader('user-agent'));
604604
}
605605

606+
/**
607+
* @group #27
608+
*/
609+
public function testContentTypeIsNotReplaced()
610+
{
611+
$this->assertFalse(
612+
$this->httpClient->getHeader('Content-Type'),
613+
'Content-Type is null if no request was made'
614+
);
615+
616+
$expectedContentType = 'text/xml; charset=utf-8';
617+
$this->httpClient->setHeaders(['Content-Type' => $expectedContentType]);
618+
619+
$this->setServerResponseTo(true);
620+
$this->assertTrue($this->xmlrpcClient->call('method'));
621+
$this->assertSame($expectedContentType, $this->httpClient->getHeader('Content-Type'));
622+
}
623+
624+
/**
625+
* @group #27
626+
*/
627+
public function testAcceptIsNotReplaced()
628+
{
629+
$this->assertFalse(
630+
$this->httpClient->getHeader('Accept'),
631+
'Accept header is null if no request was made'
632+
);
633+
634+
$expectedAccept = 'text/xml';
635+
$this->httpClient->setHeaders(['Accept' => $expectedAccept]);
636+
637+
$this->setServerResponseTo(true);
638+
$this->assertTrue($this->xmlrpcClient->call('method'));
639+
$this->assertSame($expectedAccept, $this->httpClient->getHeader('Accept'));
640+
}
641+
606642
/**
607643
* @group ZF-8478
608644
*/

0 commit comments

Comments
 (0)