-
-
Notifications
You must be signed in to change notification settings - Fork 452
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
111 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Sentry\Spotlight; | ||
|
||
use Sentry\HttpClient\Request; | ||
use Sentry\HttpClient\Response; | ||
|
||
/** | ||
* @internal | ||
*/ | ||
class SpotlightClient | ||
{ | ||
public static function sendRequest(Request $request, string $url): Response | ||
{ | ||
if (!\extension_loaded('curl')) { | ||
throw new \RuntimeException('The cURL PHP extension must be enabled to use the SpotlightClient.'); | ||
} | ||
|
||
$requestData = $request->getStringBody(); | ||
if ($requestData === null) { | ||
throw new \RuntimeException('The request data is empty.'); | ||
} | ||
|
||
$curlHandle = curl_init(); | ||
|
||
curl_setopt($curlHandle, \CURLOPT_URL, $url); | ||
curl_setopt($curlHandle, \CURLOPT_HTTPHEADER, [ | ||
'Content-Type: application/x-sentry-envelope', | ||
]); | ||
curl_setopt($curlHandle, \CURLOPT_TIMEOUT, 2.0); | ||
curl_setopt($curlHandle, \CURLOPT_CONNECTTIMEOUT, 1.0); | ||
curl_setopt($curlHandle, \CURLOPT_ENCODING, ''); | ||
curl_setopt($curlHandle, \CURLOPT_POST, true); | ||
curl_setopt($curlHandle, \CURLOPT_POSTFIELDS, $requestData); | ||
curl_setopt($curlHandle, \CURLOPT_RETURNTRANSFER, true); | ||
curl_setopt($curlHandle, \CURLOPT_HTTP_VERSION, \CURL_HTTP_VERSION_1_1); | ||
|
||
$body = curl_exec($curlHandle); | ||
|
||
if ($body === false) { | ||
$errorCode = curl_errno($curlHandle); | ||
$error = curl_error($curlHandle); | ||
curl_close($curlHandle); | ||
|
||
$message = 'cURL Error (' . $errorCode . ') ' . $error; | ||
|
||
return new Response(0, [], $message); | ||
} | ||
|
||
$statusCode = curl_getinfo($curlHandle, \CURLINFO_HTTP_CODE); | ||
|
||
curl_close($curlHandle); | ||
|
||
return new Response($statusCode, [], ''); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters