diff --git a/proxy_scraper_checker/proxy.py b/proxy_scraper_checker/proxy.py index a84b01f..a50c59e 100644 --- a/proxy_scraper_checker/proxy.py +++ b/proxy_scraper_checker/proxy.py @@ -55,7 +55,10 @@ class Proxy: raise_for_status=True, timeout=settings.timeout, fallback_charset_resolver=fallback_charset_resolver, - ) as session, session.get(settings.check_website) as response: + ) as session, session.get( + settings.check_website, + headers=settings.check_website_type.headers, + ) as response: content = await response.read() self.timeout = perf_counter() - start if settings.check_website_type == CheckWebsiteType.HTTPBIN_IP: diff --git a/proxy_scraper_checker/settings.py b/proxy_scraper_checker/settings.py index 8e4d80b..cab1ab8 100644 --- a/proxy_scraper_checker/settings.py +++ b/proxy_scraper_checker/settings.py @@ -8,6 +8,7 @@ import math import stat import sys from pathlib import Path +from types import MappingProxyType from typing import ( TYPE_CHECKING, Callable, @@ -23,7 +24,7 @@ from urllib.parse import urlparse import attrs import platformdirs -from aiohttp import ClientSession, ClientTimeout +from aiohttp import ClientSession, ClientTimeout, hdrs from aiohttp_socks import ProxyType from typing_extensions import Any, Literal, Self @@ -47,7 +48,7 @@ def _get_supported_max_connections() -> Optional[int]: ): return 512 return None - import resource # noqa: PLC0415 + import resource # type: ignore[unreachable, unused-ignore] # noqa: PLC0415 soft_limit, hard_limit = resource.getrlimit(resource.RLIMIT_NOFILE) logger.debug( @@ -113,19 +114,33 @@ def _sources_converter( class CheckWebsiteType(enum.Enum): - UNKNOWN = enum.auto() - PLAIN_IP = enum.auto() + UNKNOWN = enum.auto(), False, False, None + PLAIN_IP = enum.auto(), True, True, None """https://checkip.amazonaws.com""" - HTTPBIN_IP = enum.auto() + HTTPBIN_IP = ( + enum.auto(), + True, + True, + MappingProxyType({hdrs.ACCEPT: "application/json"}), + ) """https://httpbin.org/ip""" - @property - def supports_geolocation(self) -> bool: - return self != CheckWebsiteType.UNKNOWN + def __init__( + self, + _: object, + supports_geolocation: bool, # noqa: FBT001 + supports_anonymity: bool, # noqa: FBT001 + headers: Optional[Mapping[str, str]], + /, + ) -> None: + self.supports_geolocation = supports_geolocation + self.supports_anonymity = supports_anonymity + self.headers = headers - @property - def supports_anonymity(self) -> bool: - return self != CheckWebsiteType.UNKNOWN + def __new__(cls, value: object, *_: Any) -> Self: + member = object.__new__(cls) + member._value_ = value + return member async def _get_check_website_type_and_real_ip( diff --git a/ruff.toml b/ruff.toml index 94ac1e1..2975783 100644 --- a/ruff.toml +++ b/ruff.toml @@ -53,7 +53,7 @@ ignore-init-module-imports = true select = ["ALL"] [lint.flake8-self] -ignore-names = [] +ignore-names = ["_name_", "_value_"] [lint.isort] combine-as-imports = true