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

Commit 992adb0

Browse files
committed
Merge branch 'fix/#27-fix-memory-leak-in-header-creation-logic' into develop
Forward port #27
2 parents b6182e7 + 843ea43 commit 992adb0

File tree

3 files changed

+73
-8
lines changed

3 files changed

+73
-8
lines changed

CHANGELOG.md

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ All notable changes to this project will be documented in this file, in reverse
2020

2121
- Nothing.
2222

23-
## 2.6.1 - TBD
23+
## 2.6.2 - TBD
2424

2525
### Added
2626

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

3939
- Nothing.
4040

41+
## 2.6.1 - 2017-08-11
42+
43+
### Added
44+
45+
- Nothing.
46+
47+
### Deprecated
48+
49+
- Nothing.
50+
51+
### Removed
52+
53+
- Nothing.
54+
55+
### Fixed
56+
57+
- [#27](https://github.com/zendframework/zend-xmlrpc/pull/19) fixed a memory leak
58+
caused by repetitive addition of `Accept` and `Content-Type` headers on subsequent
59+
HTTP requests produced by the `Zend\XmlRpc\Client`.
60+
4161
## 2.6.0 - 2016-06-21
4262

4363
### Added

src/Client.php

Lines changed: 16 additions & 7 deletions
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

Lines changed: 36 additions & 0 deletions
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)