Skip to content

Commit e3ce5e0

Browse files
committed
Merge pull request #567 from Topface/persistent-body-reuse-fix
Fixed request body reuse in http transport
2 parents 6297d82 + b10b268 commit e3ce5e0

File tree

3 files changed

+36
-0
lines changed

3 files changed

+36
-0
lines changed

changes.txt

+3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
CHANGES
22

3+
2014-03-11
4+
- Fixed request body reuse in http transport
5+
36
2014-03-08
47
- Release v1.0.1.1
58
- Enable goecluster-facet again as now compatible with elasticsearch 1.0 on travis

lib/Elastica/Transport/Http.php

+2
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,8 @@ public function exec(Request $request, array $params)
112112
$content = str_replace('\/', '/', $content);
113113

114114
curl_setopt($conn, CURLOPT_POSTFIELDS, $content);
115+
} else {
116+
curl_setopt($conn, CURLOPT_POSTFIELDS, '');
115117
}
116118

117119
curl_setopt($conn, CURLOPT_NOBODY, $httpMethod == 'HEAD');

test/lib/Elastica/Test/Transport/HttpTest.php

+31
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44

55
use Elastica\Client;
66
use Elastica\Document;
7+
use Elastica\Query;
8+
use Elastica\ResultSet;
79
use Elastica\Test\Base as BaseTest;
810
use Elastica\Exception\ResponseException;
911

@@ -180,4 +182,33 @@ public function testWithoutProxy()
180182
$this->assertEquals(200, $transferInfo['http_code']);
181183
}
182184

185+
public function testBodyReuse()
186+
{
187+
$client = new Client();
188+
189+
$index = $client->getIndex('elastica_body_reuse_test');
190+
191+
$index->create(array(), true);
192+
193+
$type = $index->getType('test');
194+
$type->addDocument(new Document(1, array('test' => 'test')));
195+
196+
$index->refresh();
197+
198+
$resultSet = $index->search(array(
199+
'query' => array(
200+
'query_string' => array(
201+
'query' => 'pew pew pew',
202+
),
203+
),
204+
));
205+
206+
$this->assertEquals(0, $resultSet->getTotalHits());
207+
208+
$response = $index->request('/_search', 'POST');
209+
$resultSet = new ResultSet($response, Query::create(array()));
210+
211+
$this->assertEquals(1, $resultSet->getTotalHits());
212+
}
213+
183214
}

0 commit comments

Comments
 (0)