Skip to content

Commit

Permalink
Merge pull request #79 from anensshiya-govinthas-ck/curl_returntransfer
Browse files Browse the repository at this point in the history
Set CURLOPT_RETURNTRANSFER to true
  • Loading branch information
jcchavezs authored Jul 11, 2018
2 parents 8de0986 + 7f03287 commit 1746ced
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/Zipkin/Reporters/Http/CurlFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,9 @@ public function build(array $options = [])
'Content-Type: application/json',
'Content-Length: ' . strlen($payload),
]);
curl_setopt($handle, CURLOPT_RETURNTRANSFER, true);

if (curl_exec($handle) === true) {
if (curl_exec($handle) !== false) {
$statusCode = curl_getinfo($handle, CURLINFO_HTTP_CODE);
curl_close($handle);

Expand Down
33 changes: 33 additions & 0 deletions tests/Integration/Reporters/Http/CurlFactoryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -80,4 +80,37 @@ public function testHttpReportingFailsDueToUnreachableUrl()

$curlClient('');
}

public function testHttpReportingSilentlySendTraces()
{
$t = $this;

$server = HttpTestServer::create(
function (RequestInterface $request, ResponseInterface &$response) use ($t) {
$t->assertEquals('POST', $request->getMethod());
$t->assertEquals('application/json', $request->getHeader('Content-Type')[0]);
$response = $response->withStatus(202);
$response->getBody()->write('Accepted');
}
);

$server->start();

try {
$curlClient = CurlFactory::create()->build([
'endpoint_url' => $server->getUrl(),
]);

ob_start();
$curlClient(json_encode([]));
$output = ob_get_clean();
$this->assertEmpty($output);
} catch (Exception $e) {
$server->stop();

$this->fail($e->getMessage());
} finally {
$server->stop();
}
}
}

0 comments on commit 1746ced

Please sign in to comment.