43 lines
1.2 KiB
Python
43 lines
1.2 KiB
Python
DEFAULT_USER_AGENT = (
|
|
"Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/150.0.0.0 Safari/537.36"
|
|
)
|
|
|
|
DEFAULT_ACCEPT = (
|
|
"text/html,"
|
|
"application/xhtml+xml,"
|
|
"application/xml;q=0.9,"
|
|
"image/avif,"
|
|
"image/webp,"
|
|
"image/apng,"
|
|
"*/*;q=0.8,"
|
|
"application/signed-exchange;v=b3;q=0.7"
|
|
)
|
|
|
|
DEFAULT_HEADERS = {
|
|
"Accept": DEFAULT_ACCEPT,
|
|
"Accept-Encoding": "gzip, deflate, br, zstd",
|
|
"Accept-Language": "en-US,en;q=0.9,ru-RU;q=0.8,ru;q=0.7,uk;q=0.6",
|
|
"Cache-Control": "max-age=0",
|
|
"Connection": "keep-alive",
|
|
"Host": None,
|
|
"Referer": None,
|
|
"Sec-Fetch-Dest": "document",
|
|
"Sec-Fetch-Mode": "navigate",
|
|
"Sec-Fetch-Site": "none",
|
|
"Sec-Fetch-User": "?1",
|
|
"Upgrade-Insecure-Requests": "1",
|
|
"User-Agent": DEFAULT_USER_AGENT,
|
|
"sec-ch-ua": '"Not;A=Brand";v="8", "Chromium";v="150", "Google Chrome";v="150"',
|
|
"sec-ch-ua-mobile": "?0",
|
|
"sec-ch-ua-platform": '"Linux"',
|
|
}
|
|
|
|
|
|
def build_headers(host: str, *, user_agent: str | None = None) -> dict[str, str]:
|
|
result = DEFAULT_HEADERS.copy()
|
|
result["Host"] = host
|
|
result["Referer"] = f"https://{host}/"
|
|
if user_agent is not None:
|
|
result["User-Agent"] = user_agent
|
|
return result
|