Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Add support timeouts in milliseconds for HTTP client #1783

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
16 changes: 14 additions & 2 deletions src/HttpClient/HttpClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -64,15 +64,27 @@ public function sendRequest(Request $request, Options $options): Response
curl_setopt($curlHandle, \CURLOPT_URL, $dsn->getEnvelopeApiEndpointUrl());
curl_setopt($curlHandle, \CURLOPT_HTTPHEADER, $requestHeaders);
curl_setopt($curlHandle, \CURLOPT_USERAGENT, $this->sdkIdentifier . '/' . $this->sdkVersion);
curl_setopt($curlHandle, \CURLOPT_TIMEOUT, $options->getHttpTimeout());
curl_setopt($curlHandle, \CURLOPT_CONNECTTIMEOUT, $options->getHttpConnectTimeout());
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_HEADERFUNCTION, $responseHeaderCallback);
curl_setopt($curlHandle, \CURLOPT_HTTP_VERSION, \CURL_HTTP_VERSION_1_1);

$httpTimeout = $options->getHttpTimeout();
if ($httpTimeout < 1.0) {
curl_setopt($curlHandle, \CURLOPT_TIMEOUT_MS, $httpTimeout * 1000);
} else {
curl_setopt($curlHandle, \CURLOPT_TIMEOUT, $httpTimeout);
}

$connectTimeout = $options->getHttpConnectTimeout();
if ($connectTimeout < 1.0) {
curl_setopt($curlHandle, \CURLOPT_CONNECTTIMEOUT_MS, $connectTimeout * 1000);
} else {
curl_setopt($curlHandle, \CURLOPT_CONNECTTIMEOUT, $connectTimeout);
}

$httpSslVerifyPeer = $options->getHttpSslVerifyPeer();
if (!$httpSslVerifyPeer) {
curl_setopt($curlHandle, \CURLOPT_SSL_VERIFYPEER, false);
Expand Down
14 changes: 14 additions & 0 deletions tests/OptionsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -341,6 +341,13 @@ static function (): void {},
'setHttpTimeout',
];

yield [
'http_timeout',
0.2,
'getHttpTimeout',
'setHttpTimeout',
];

yield [
'http_connect_timeout',
1,
Expand All @@ -355,6 +362,13 @@ static function (): void {},
'setHttpConnectTimeout',
];

yield [
'http_connect_timeout',
0.2,
'getHttpConnectTimeout',
'setHttpConnectTimeout',
];

yield [
'http_ssl_verify_peer',
false,
Expand Down
Loading