Skip to content

Commit 9dda289

Browse files
committed
fix: add timeout and scope retry to connection errors in TurnstileClient
- Add ->timeout(5) to bound max wall time to ~15s during Cloudflare outages - Restrict retry to ConnectionException only so success:false responses (valid HTTP 200) do not trigger wasteful retries
1 parent 48dd294 commit 9dda289

1 file changed

Lines changed: 3 additions & 1 deletion

File tree

app/Services/TurnstileClient.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
* limitations under the License.
1414
**/
1515

16+
use Illuminate\Http\Client\ConnectionException;
1617
use Illuminate\Support\Facades\Http;
1718
use RyanChandler\LaravelCloudflareTurnstile\Contracts\ClientInterface;
1819
use RyanChandler\LaravelCloudflareTurnstile\Responses\SiteverifyResponse;
@@ -30,7 +31,8 @@ public function __construct(private string $secret)
3031

3132
public function siteverify(string $token): SiteverifyResponse
3233
{
33-
$response = Http::retry(3, 100)
34+
$response = Http::timeout(5)
35+
->retry(3, 100, fn($e) => $e instanceof ConnectionException)
3436
->asForm()
3537
->acceptJson()
3638
->post('https://challenges.cloudflare.com/turnstile/v0/siteverify', [

0 commit comments

Comments
 (0)