Skip to content

Commit

Permalink
Add User-Agent header with Hatch, Python and HTTPX versions
Browse files Browse the repository at this point in the history
  • Loading branch information
hugovk committed Nov 26, 2024
1 parent 6bc4bbe commit fc0103d
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions src/hatch/index/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@

import hyperlink

from hatch._version import __version__

if TYPE_CHECKING:
import httpx

Expand Down Expand Up @@ -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,
)
Expand Down

0 comments on commit fc0103d

Please sign in to comment.