Merge pull request #18714 from OAburub/patch

fix: make SSL Verificiation async
This commit is contained in:
Tim Baek 2025-10-30 10:47:21 -07:00 committed by GitHub
commit 16af088f4e
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -16,6 +16,8 @@ from typing import (
Union, Union,
Literal, Literal,
) )
from fastapi.concurrency import run_in_threadpool
import aiohttp import aiohttp
import certifi import certifi
import validators import validators
@ -142,13 +144,13 @@ class RateLimitMixin:
class URLProcessingMixin: class URLProcessingMixin:
def _verify_ssl_cert(self, url: str) -> bool: async def _verify_ssl_cert(self, url: str) -> bool:
"""Verify SSL certificate for a URL.""" """Verify SSL certificate for a URL."""
return verify_ssl_cert(url) return await run_in_threadpool(verify_ssl_cert, url)
async def _safe_process_url(self, url: str) -> bool: async def _safe_process_url(self, url: str) -> bool:
"""Perform safety checks before processing a URL.""" """Perform safety checks before processing a URL."""
if self.verify_ssl and not self._verify_ssl_cert(url): if self.verify_ssl and not await self._verify_ssl_cert(url):
raise ValueError(f"SSL certificate verification failed for {url}") raise ValueError(f"SSL certificate verification failed for {url}")
await self._wait_for_rate_limit() await self._wait_for_rate_limit()
return True return True