Skip to content

Commit

Permalink
Merge pull request #567 from Topface/persistent-body-reuse-fix
Browse files Browse the repository at this point in the history
Fixed request body reuse in http transport
  • Loading branch information
ruflin committed Mar 13, 2014
2 parents 6297d82 + b10b268 commit e3ce5e0
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 0 deletions.
3 changes: 3 additions & 0 deletions changes.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
CHANGES

2014-03-11
- Fixed request body reuse in http transport

2014-03-08
- Release v1.0.1.1
- Enable goecluster-facet again as now compatible with elasticsearch 1.0 on travis
Expand Down
2 changes: 2 additions & 0 deletions lib/Elastica/Transport/Http.php
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,8 @@ public function exec(Request $request, array $params)
$content = str_replace('\/', '/', $content);

curl_setopt($conn, CURLOPT_POSTFIELDS, $content);
} else {
curl_setopt($conn, CURLOPT_POSTFIELDS, '');
}

curl_setopt($conn, CURLOPT_NOBODY, $httpMethod == 'HEAD');
Expand Down
31 changes: 31 additions & 0 deletions test/lib/Elastica/Test/Transport/HttpTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

use Elastica\Client;
use Elastica\Document;
use Elastica\Query;
use Elastica\ResultSet;
use Elastica\Test\Base as BaseTest;
use Elastica\Exception\ResponseException;

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

public function testBodyReuse()
{
$client = new Client();

$index = $client->getIndex('elastica_body_reuse_test');

$index->create(array(), true);

$type = $index->getType('test');
$type->addDocument(new Document(1, array('test' => 'test')));

$index->refresh();

$resultSet = $index->search(array(
'query' => array(
'query_string' => array(
'query' => 'pew pew pew',
),
),
));

$this->assertEquals(0, $resultSet->getTotalHits());

$response = $index->request('/_search', 'POST');
$resultSet = new ResultSet($response, Query::create(array()));

$this->assertEquals(1, $resultSet->getTotalHits());
}

}

0 comments on commit e3ce5e0

Please sign in to comment.