Skip to content

Add default User-Agent for integration HTTP requests#46

Open
TheRealAgentK wants to merge 3 commits into
masterfrom
feat/default-user-agent
Open

Add default User-Agent for integration HTTP requests#46
TheRealAgentK wants to merge 3 commits into
masterfrom
feat/default-user-agent

Conversation

@TheRealAgentK

@TheRealAgentK TheRealAgentK commented Jun 22, 2026

Copy link
Copy Markdown
Collaborator

Summary

Adds SDK-level User-Agent handling for integration HTTP requests made through ExecutionContext.fetch().

Default behavior

When an integration does not provide a User-Agent, the SDK now sends a versioned Autohive default instead of relying on aiohttp's default:

AutohiveIntegrationsSDK/<sdk-version>

When the request is made from a registered integration handler, the SDK also includes the integration identity from config.json:

AutohiveIntegrationsSDK/<sdk-version> <integration-name>/<integration-version>

Example:

AutohiveIntegrationsSDK/2.0.0 github/1.0.0

Integration name/version values are sanitized for safe User-Agent product tokens.

Custom User-Agent support

Adds a convenience user_agent argument to context.fetch():

await context.fetch(
    url,
    user_agent="MyIntegration/1.0"
)

Existing header-based usage is still supported:

await context.fetch(
    url,
    headers={"User-Agent": "MyIntegration/1.0"}
)

Precedence is:

  1. Explicit headers["User-Agent"] / headers["user-agent"]
  2. user_agent="..."
  3. SDK default

This means integrations that already set a custom User-Agent do not need to change and keep their existing behavior.

Context identity handling

The integration identity is applied only while a handler is executing and then restored, so reusing an ExecutionContext across integrations does not leak the previous integration identity.

CI/test dependency note

Constrains the test extra to aiohttp<3.13.4 because the current aioresponses release is incompatible with newer aiohttp ClientResponse constructor changes in CI. The SDK runtime dependency remains unconstrained (aiohttp).

Docs

  • Documents default User-Agent behavior and the new user_agent argument in the manual docs.
  • Regenerates tracked API docs with pdoc.

Testing

  • .venv/bin/python -m pytest tests/ -v
  • .venv/bin/python -m pytest tests/ -v --cov=autohive_integrations_sdk --cov-report=term-missing
    • 83 passed
    • 100% coverage
  • git diff --check

@github-actions

Copy link
Copy Markdown

Coverage — c16a3b7 (test: pin aiohttp for aioresponses compatibility) by @TheRealAgentK

Total coverage: 100%

File Stmts Miss Cover Missing
src/autohive_integrations_sdk/__init__.py 2 0 100%
src/autohive_integrations_sdk/integration.py 389 0 100%

@TheRealAgentK TheRealAgentK requested a review from Olwiba June 22, 2026 15:22
@TheRealAgentK TheRealAgentK added this to the 3.0.0 milestone Jun 22, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants