Skip to content

Commit

Permalink
send project-specific User-Agent HTTP header #853 (#1075)
Browse files Browse the repository at this point in the history
  • Loading branch information
jakob-keller authored Jan 19, 2024
1 parent 743c26f commit c772f4b
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 4 deletions.
4 changes: 4 additions & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
Changes
-------

2.11.0 (2024-01-19)
^^^^^^^^^^^^^^^^^^^
* send project-specific `User-Agent` HTTP header #853

2.10.0 (2024-01-18)
^^^^^^^^^^^^^^^^^^^
* bump botocore dependency specification
Expand Down
2 changes: 1 addition & 1 deletion aiobotocore/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = '2.10.0'
__version__ = '2.11.0'
16 changes: 14 additions & 2 deletions aiobotocore/session.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
from botocore import UNSIGNED, translate
from botocore import UNSIGNED
from botocore import __version__ as botocore_version
from botocore import translate
from botocore.exceptions import PartialCredentialsError
from botocore.session import EVENT_ALIASES, ServiceModel
from botocore.session import Session as _SyncSession
from botocore.session import UnknownServiceError, copy

from . import retryhandler
from . import __version__, retryhandler
from .client import AioBaseClient, AioClientCreator
from .configprovider import AioSmartDefaultsConfigStoreFactory
from .credentials import AioCredentials, create_credential_resolver
Expand Down Expand Up @@ -43,6 +45,16 @@ def __init__(
session_vars, event_hooks, include_builtin_handlers, profile
)

self._set_user_agent_for_session()

def _set_user_agent_for_session(self):
# Mimic approach taken by AWS's aws-cli project
# https://github.com/aws/aws-cli/blob/b862122c76a3f280ff34e93c9dcafaf964e7bf9b/awscli/clidriver.py#L84

self.user_agent_name = 'aiobotocore'
self.user_agent_version = __version__
self.user_agent_extra = 'botocore/%s' % botocore_version

def _create_token_resolver(self):
return create_token_resolver(self)

Expand Down
9 changes: 8 additions & 1 deletion tests/test_session.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import pytest
from _pytest.logging import LogCaptureFixture

from aiobotocore import httpsession
from aiobotocore import __version__, httpsession
from aiobotocore.config import AioConfig
from aiobotocore.session import AioSession

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

assert 'sleeping for' in caplog.text


@pytest.mark.moto
async def test_set_user_agent_for_session(session: AioSession):
assert session.user_agent_name == "aiobotocore"
assert session.user_agent_version == __version__
assert session.user_agent_extra.startswith("botocore/")

0 comments on commit c772f4b

Please sign in to comment.