More thorough URL checks

This commit is contained in:
Thomas Sileo 2022-07-15 20:50:27 +02:00
parent 0d3b41272f
commit c160b75851
6 changed files with 25 additions and 6 deletions

View file

@ -24,7 +24,7 @@ class InvalidURLError(Exception):
pass
@functools.lru_cache
@functools.lru_cache(maxsize=256)
def _getaddrinfo(hostname: str, port: int) -> str:
try:
ip_address = str(ipaddress.ip_address(hostname))
@ -65,7 +65,7 @@ def is_url_valid(url: str) -> bool:
return True
def check_url(url: str, debug: bool = False) -> None:
def check_url(url: str) -> None:
logger.debug(f"check_url {url=}")
if not is_url_valid(url):
raise InvalidURLError(f'"{url}" is invalid')

View file

@ -8,6 +8,7 @@ from loguru import logger
from app import config
from app.utils.datetime import now
from app.utils.url import check_url
from app.utils.url import is_url_valid
from app.utils.url import make_abs
@ -46,6 +47,8 @@ async def discover_webmention_endpoint(url: str) -> str | None:
Passes all the tests at https://webmention.rocks!
"""
check_url(url)
wurl = await _discover_webmention_endoint(url)
if wurl is None:
return None