Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 18 additions & 8 deletions agent/src/EnvelopeForwarder.php
Original file line number Diff line number Diff line change
Expand Up @@ -92,17 +92,27 @@ public function forward(Envelope $envelope): PromiseInterface
'sentry_key=' . $dsn->getPublicKey(),
];

// @TODO: Implement any number of missing options like the user-agent, encoding, proxy etc.
$headers = [
'User-Agent' => $client,
'Content-Type' => Envelope::CONTENT_TYPE,
'X-Sentry-Auth' => 'Sentry ' . implode(', ', $authHeader),
];

$body = (string) $envelope;

if (\extension_loaded('zlib')) {
$compressedBody = gzcompress($body, -1, \ZLIB_ENCODING_GZIP);

if ($compressedBody !== false) {
$headers['Content-Encoding'] = 'gzip';
$body = $compressedBody;
}
}

// @TODO: We might want to replace this Browser API with a cURL implementation using curl_multi_exec
return (new Browser())->withTimeout($this->timeout)->post(
$dsn->getEnvelopeApiEndpointUrl(),
[
'User-Agent' => $client,
'Content-Type' => Envelope::CONTENT_TYPE,
'X-Sentry-Auth' => 'Sentry ' . implode(', ', $authHeader),
],
(string) $envelope
$headers,
$body
)->then(function (ResponseInterface $response) use ($rateLimiter) {
$rateLimiter->handleResponse(
new Response($response->getStatusCode(), $response->getHeaders(), $response->getStatusCode() > 400 ? $response->getBody()->getContents() : '')
Expand Down
21 changes: 21 additions & 0 deletions agent/tests/AgentForwardingTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,27 @@ public function testAgentForwardsMultipleEnvelopesToUpstream(): void
$this->assertEquals(2, $serverOutput['request_count']);
}

public function testAgentCompressesEnvelopeToUpstream(): void
{
if (!\extension_loaded('zlib')) {
$this->markTestSkipped('The zlib extension is required to test envelope compression.');
}

$serverAddress = $this->startTestServer();

$dsn = "http://publickey:@{$serverAddress}/200";

$this->startTestAgent();
$this->sendEnvelopeToAgent($this->createEnvelope($dsn, 'Compressed message'));
$this->stopTestAgent();

$serverOutput = $this->stopTestServer();

$this->assertTrue($serverOutput['compressed']);
$this->assertEquals('gzip', $serverOutput['headers']['Content-Encoding']);
$this->assertStringContainsString('Compressed message', $serverOutput['body']);
}

public function testAgentRespectsRateLimiting(): void
{
$serverAddress = $this->startTestServer();
Expand Down
Binary file modified bin/sentry-agent
Binary file not shown.
2 changes: 1 addition & 1 deletion bin/sentry-agent.sig
Original file line number Diff line number Diff line change
@@ -1 +1 @@
F3CE4B37DC4AC5C3890CC9497A95351E29641DA3BAD0699B727A8D77002C6B36913EB82B55ACB1BA683D27CBAF123007D2CE68AA10773CF4012292D38E5F1904
C779A799D4389C7E52048F1271B64B01DFFBD75C59E111C5DB180004E980D2CD6F56D59FDD14825EE3F6F8F002F5405D0CB97FB46199D730C7FDB77D4BB5A9A4
Loading