From fc0103dcc9b13b3f5aefdfd49c4e44a597a9592b Mon Sep 17 00:00:00 2001 From: Hugo van Kemenade <1324225+hugovk@users.noreply.github.com> Date: Tue, 26 Nov 2024 14:05:09 +0200 Subject: [PATCH] Add User-Agent header with Hatch, Python and HTTPX versions --- src/hatch/index/core.py | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/hatch/index/core.py b/src/hatch/index/core.py index c5a231bae..226208bca 100644 --- a/src/hatch/index/core.py +++ b/src/hatch/index/core.py @@ -5,6 +5,8 @@ import hyperlink +from hatch._version import __version__ + if TYPE_CHECKING: import httpx @@ -47,11 +49,19 @@ def __init__(self, repo: str, *, user='', auth='', ca_cert=None, client_cert=Non @cached_property def client(self) -> httpx.Client: + import platform + import httpx from hatch.utils.network import DEFAULT_TIMEOUT + user_agent = ( + f'Hatch/{__version__} ' + f'{platform.python_implementation()}/{platform.python_version()} ' + f'HTTPX/{httpx.__version__}' + ) return httpx.Client( + headers={'User-Agent': user_agent}, transport=httpx.HTTPTransport(retries=3, verify=self.__verify, cert=self.__cert), timeout=DEFAULT_TIMEOUT, )