Skip to content

Commit 5265b3c

Browse files
committed
Reuse CAPTCHA verification API connections
1 parent 12d0a03 commit 5265b3c

1 file changed

Lines changed: 4 additions & 3 deletions

File tree

backend/api/captcha.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,16 @@ static SECRET_KEY: LazyLock<String> = LazyLock::new(|| {
1010
.expect("environment variable `TURNSTILE_SECRET_KEY` should be a valid string")
1111
});
1212

13+
/// The client for connecting to the CAPTCHA verification API.
14+
static CAPTCHA_CLIENT: LazyLock<reqwest::Client> = LazyLock::new(|| reqwest::Client::new());
15+
1316
/// Returns whether a Cloudflare Turnstile token is valid.
1417
///
1518
/// # Errors
1619
///
1720
/// Returns an error if the verification request fails or cannot be processed.
1821
pub(crate) async fn verify(token: &str) -> Result<bool, reqwest::Error> {
19-
let client = reqwest::Client::new();
20-
21-
let outcome: Value = client
22+
let outcome: Value = CAPTCHA_CLIENT
2223
.post("https://challenges.cloudflare.com/turnstile/v0/siteverify")
2324
.json(&json!({
2425
"secret": *SECRET_KEY,

0 commit comments

Comments
 (0)