DarkGhostHunter / Captchavel

Integrate reCAPTCHA into your Laravel app better than the Big G itself!
MIT License
95 stars 17 forks source link

Use Async request to reCAPTCHA servers on V3 #42

Closed DarkGhostHunter closed 3 years ago

DarkGhostHunter commented 3 years ago

Currently, the library uses the default Laravel HTTP Client. The client supports async() request, which return a promise which result can be retrieved later. This is a nice article explaining how. This would avoid blocking the request by waiting the response from reCAPTCHA servers.

In theory, it should be possible to queue the async reques, and resolve it only if the user requires to check the score. Since the user interacts with ReCaptchaResponse directly, the changes underneath would be opaque; nothing would change on the user-land.

After the response is sent, the request would be forcefully cancelled to avoid lingering pending requests (specially under Laravel Octane or similar). This means the middleware should have a terminate() method in which the response is forcefully cancelled.

public function terminate($request, $response)
{
    $this->captchavel->cancelPendingRequest();
}
DarkGhostHunter commented 3 years ago

Done in #43