Skip to content

Commit c772f4b

Browse files
authored
send project-specific User-Agent HTTP header #853 (#1075)
1 parent 743c26f commit c772f4b

4 files changed

Lines changed: 27 additions & 4 deletions

File tree

CHANGES.rst

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
Changes
22
-------
33

4+
2.11.0 (2024-01-19)
5+
^^^^^^^^^^^^^^^^^^^
6+
* send project-specific `User-Agent` HTTP header #853
7+
48
2.10.0 (2024-01-18)
59
^^^^^^^^^^^^^^^^^^^
610
* bump botocore dependency specification

aiobotocore/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
__version__ = '2.10.0'
1+
__version__ = '2.11.0'

aiobotocore/session.py

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
1-
from botocore import UNSIGNED, translate
1+
from botocore import UNSIGNED
2+
from botocore import __version__ as botocore_version
3+
from botocore import translate
24
from botocore.exceptions import PartialCredentialsError
35
from botocore.session import EVENT_ALIASES, ServiceModel
46
from botocore.session import Session as _SyncSession
57
from botocore.session import UnknownServiceError, copy
68

7-
from . import retryhandler
9+
from . import __version__, retryhandler
810
from .client import AioBaseClient, AioClientCreator
911
from .configprovider import AioSmartDefaultsConfigStoreFactory
1012
from .credentials import AioCredentials, create_credential_resolver
@@ -43,6 +45,16 @@ def __init__(
4345
session_vars, event_hooks, include_builtin_handlers, profile
4446
)
4547

48+
self._set_user_agent_for_session()
49+
50+
def _set_user_agent_for_session(self):
51+
# Mimic approach taken by AWS's aws-cli project
52+
# https://github.com/aws/aws-cli/blob/b862122c76a3f280ff34e93c9dcafaf964e7bf9b/awscli/clidriver.py#L84
53+
54+
self.user_agent_name = 'aiobotocore'
55+
self.user_agent_version = __version__
56+
self.user_agent_extra = 'botocore/%s' % botocore_version
57+
4658
def _create_token_resolver(self):
4759
return create_token_resolver(self)
4860

tests/test_session.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
import pytest
44
from _pytest.logging import LogCaptureFixture
55

6-
from aiobotocore import httpsession
6+
from aiobotocore import __version__, httpsession
77
from aiobotocore.config import AioConfig
88
from aiobotocore.session import AioSession
99

@@ -52,3 +52,10 @@ async def test_retry(
5252
await client.get_object(Bucket='foo', Key='bar')
5353

5454
assert 'sleeping for' in caplog.text
55+
56+
57+
@pytest.mark.moto
58+
async def test_set_user_agent_for_session(session: AioSession):
59+
assert session.user_agent_name == "aiobotocore"
60+
assert session.user_agent_version == __version__
61+
assert session.user_agent_extra.startswith("botocore/")

0 commit comments

Comments
 (0)