fix: update code and docstrings to remove the old google referer logic

This commit is contained in:
Karim shoair
2026-03-09 00:25:19 +02:00
parent b547e04207
commit a929de6ca4
7 changed files with 40 additions and 79 deletions
@@ -5,7 +5,6 @@ Functions related to generating headers and fingerprints generally
from functools import lru_cache
from platform import system as platform_system
from tld import get_tld, Result
from browserforge.headers import Browser, HeaderGenerator
from browserforge.headers.generator import SUPPORTED_OPERATING_SYSTEMS
@@ -18,34 +17,6 @@ chromium_version = 145
chrome_version = 145
@lru_cache(10, typed=True)
def generate_convincing_referer(url: str) -> str | None:
"""Generate a convincing Google referer header
>>> generate_convincing_referer('https://www.somewebsite.com/blah')
'https://www.google.com/'
:param url: The URL you are about to fetch.
:return: Google's URL as referer, or None for localhost/IP addresses
"""
# Fixing the inaccurate return type hint in `get_tld`
extracted: Result | None = cast(Result, get_tld(url, as_object=True, fail_silently=True))
if not extracted:
return None
website_name = extracted.domain
# Skip generating referer for localhost, IP addresses, or when there's no valid domain
if not website_name or not extracted.tld or website_name in ("localhost", "127.0.0.1", "::1"):
return None
# Check if it's an IP address (simple check for IPv4)
if all(part.isdigit() for part in website_name.split(".") if part):
return None
return "https://www.google.com/"
@lru_cache(1, typed=True)
def get_os_name() -> OSName | Tuple:
"""Get the current OS name in the same format needed for browserforge, if the OS is Unknown, return None so browserforge uses all.