Skip to content

Python: case-insensitive User-Agent detection prevents duplicate headers - #8521

Open
Manohar Paturi (ManoharPaturi) wants to merge 1 commit into
microsoft:mainfrom
ManoharPaturi:fix/user-agent-header-casing
Open

Manohar Paturi (ManoharPaturi) wants to merge 1 commit into
microsoft:mainfrom
ManoharPaturi:fix/user-agent-header-casing

Conversation

@ManoharPaturi

Copy link
Copy Markdown
Contributor

Motivation & Context

Fixes #8520. exact-case "User-Agent" detection let a lowercase user-agent through, producing duplicate UA header lines.

Description & Review Guide

  • What are the major changes? the existing-header lookup is now case-insensitive and the framework token prepends to whichever variant the caller used.
  • What is the impact of these changes? one User-Agent line regardless of caller casing.
  • What do you want reviewers to focus on? the lookup change in prepend_agent_framework_to_user_agent.

Related Issue

Fixes #8520

Contribution Checklist

  • The code builds clean without any errors or warnings
  • All unit tests pass, and I have added new tests where possible
  • The PR follows the Contribution Guidelines
  • This PR is linked to an issue and there is no other open PR for this issue
  • This is not a breaking change.

prepend_agent_framework_to_user_agent looked up the exact key
"User-Agent" when deciding whether an incoming headers dict already
carries a user agent. HTTP header names are case-insensitive, so a caller
passing default_headers={"user-agent": "my-app/1.0"} (for example to
OpenAI clients or the A2A agent) ended up with two User-Agent entries:
their original one plus a new agent-framework one. httpx then sends both
header lines, and which value a server honors is undefined.

Find the existing entry case-insensitively and prepend to it in place, so
exactly one User-Agent header survives.

Copilot AI 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.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

python Usage: [Issues, PRs], Target: Python

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Python: duplicate User-Agent headers when caller passes lowercase user-agent

2 participants