Skip to content

fix(proxy): case-insensitive User-Agent header lookup in _get_user_agent_tags - #41012

Open
ege-arhan wants to merge 3 commits into
BerriAI:mainfrom
ege-arhan:fix/issue-40979
Open

fix(proxy): case-insensitive User-Agent header lookup in _get_user_agent_tags#41012
ege-arhan wants to merge 3 commits into
BerriAI:mainfrom
ege-arhan:fix/issue-40979

Conversation

@ege-arhan

Copy link
Copy Markdown

Problem

StandardLoggingPayloadSetup._get_user_agent_tags performs a case-sensitive dictionary lookup if "user-agent" in headers:. Per HTTP specifications (RFC 7230 / RFC 9110), HTTP headers are case-insensitive. When callers send capitalized headers such as User-Agent: curl/7.68.0 or User-Agent: python-requests/2.31.0, _get_user_agent_tags fails to detect the header and does not record User-Agent request tags in spend tracking or proxy request tags.

Solution

Use a case-insensitive lookup over headers.items() matching k.lower() == "user-agent" to extract the header value regardless of capitalization.

Impact

Callers sending User-Agent with any capitalization will have their client tags correctly tracked in spend logs and analytics.

Evidence

Added test case in tests/test_litellm/litellm_core_utils/test_litellm_logging.py validating that User-Agent: curl/7.68.0 correctly extracts User-Agent: curl and User-Agent: curl/7.68.0.

Fixes #40979

@ege-arhan
ege-arhan requested a review from a team September 13, 2026 16:28
@CLAassistant

Copy link
Copy Markdown

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution.


ege-arhan seems not to be a GitHub user. You need a GitHub account to be able to sign the CLA. If you have already a GitHub account, please add the email address used for this commit to your account.
You have signed the CLA already but the status is still pending? Let us recheck it.

@codspeed-hq

codspeed-hq Bot commented Sep 13, 2026

Copy link
Copy Markdown
Contributor

Merging this PR will not alter performance

✅ 31 untouched benchmarks


Comparing ege-arhan:fix/issue-40979 (d8fdd3e) with main (30f33a9)

Open in CodSpeed

@greptile-apps

greptile-apps Bot commented Sep 13, 2026

Copy link
Copy Markdown
Contributor

Greptile Summary

This PR makes User-Agent extraction case-insensitive so capitalized header names produce the expected request and spend-tracking tags

  • Replaces the exact lowercase dictionary lookup with a case-insensitive scan
  • Adds a focused regression case for User-Agent: curl/7.68.0
  • Leaves a redundant null guard and adds a test comment prohibited by repository guidance

Confidence Score: 4/5

The behavior change appears correct, but the explicit source-comment requirement must be satisfied before merging

The case-insensitive lookup and regression assertions are sound; remaining findings are limited to redundant nesting and a repository-rule violation

Files Needing Attention: litellm/litellm_core_utils/litellm_logging.py, tests/test_litellm/litellm_core_utils/test_litellm_logging.py

Important Files Changed

Filename Overview
litellm/litellm_core_utils/litellm_logging.py Correctly adds case-insensitive User-Agent lookup, but introduces an identical nested null check
tests/test_litellm/litellm_core_utils/test_litellm_logging.py Adds a meaningful regression assertion, along with an unnecessary comment that violates repository guidance

Reviews (1): Last reviewed commit: "fix(proxy): case-insensitive User-Agent ..." | Re-trigger Greptile

user_agent: Final = next(
(v for k, v in headers.items() if k.lower() == "user-agent"), None
)
if user_agent is not None:

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.

P2 Redundant null guard

The identical nested check adds needless indentation and makes this touched logic harder to read without changing behavior

Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!

assert "User-Agent: litellm" in tags
assert "User-Agent: litellm/0.1.0" in tags

# Case-insensitive header test

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.

P2 Disallowed test comment

This comment merely restates the test, violating the repository directive limiting comments to complex logic, tooling, or TODOs. Remove it before merging

Suggested change
# Case-insensitive header test

Context Used: CLAUDE.md (source)

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: e0333b7168

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

user_agent: Final = next(
(v for k, v in headers.items() if k.lower() == "user-agent"), None
)
if user_agent is not None:

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1 Badge Remove the redundant nesting layer

Remove this redundant outer guard; its identical inner check adds a nesting level even though CLAUDE.md requires early returns over deep nesting

AGENTS.md reference: AGENTS.md:L1-L1

Useful? React with 👍 / 👎.

assert "User-Agent: litellm" in tags
assert "User-Agent: litellm/0.1.0" in tags

# Case-insensitive header test

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1 Badge Remove the prohibited explanatory comment

Remove this explanatory test comment; CLAUDE.md permits comments only for complex logic, tool directives, or justified TODO/FIXME entries

AGENTS.md reference: AGENTS.md:L1-L1

Useful? React with 👍 / 👎.

@codecov

codecov Bot commented Sep 13, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

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.

[Bug]: case-insensitive User-Agent header lookup in _get_user_agent_tags

2 participants