Skip to content

Add default User-Agent for integration HTTP requests#46

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

Add default User-Agent for integration HTTP requests#46
TheRealAgentK wants to merge 5 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.14 because current aioresponses releases are compatible with aiohttp 3.13.x but not 3.14.x ClientResponse constructor changes. 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

github-actions Bot commented Jun 22, 2026

Copy link
Copy Markdown

Coverage — 61750c0 (Merge branch 'master' into feat/default-user-agent) 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

@NinosMan NinosMan left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Small comment but otherwise looks good to me 👍

Comment thread pyproject.toml Outdated

[project.optional-dependencies]
test = [
"aiohttp<3.13.4",

@NinosMan NinosMan Jun 29, 2026

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
"aiohttp<3.13.4",
"aiohttp<3.14",

Just a nit - If I understand correctly, 3.14 is a breaking change for CI. But should we be installing 3.13.5 rather than 3.13.3?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should, yes. Will change in the PR.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changed, @NinosMan in case you want to have another look, builds still pass.

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