This commit is contained in:
Vimal Sahani 2026-10-27 02:21:16 +00:00 • committed by GitHub
commit 53a6ce6ee6
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 25 additions and 5 deletions

View file

@ -7108,13 +7108,18 @@ class StandardLoggingPayloadSetup:
headers: Final = proxy_server_request.get("headers", {})
if not isinstance(headers, dict):
return None
request_headers: Final = cast( # cast-ok: request headers are untyped framework data
dict[str, str], headers
)
header_tags: Final = []
# Headers are case-insensitive per RFC 7230 / RFC 9110.
# Normalize header keys to lowercase to ensure tags are captured regardless of request casing.
normalized_headers: Final[dict[str, str]] = {
str(k).lower(): str(v)
for k, v in headers.items()
if v is not None
}
header_tags: Final[list[str]] = []
for header_name in extra_headers:
header_value = request_headers.get(header_name)
header_value = normalized_headers.get(header_name.lower())
if header_value:
header_tags.append(f"{header_name}: {header_value}")

View file

@ -3662,6 +3662,21 @@ def test_get_extra_header_tags():
assert "x-custom: my-value" in result
assert "x-empty:" not in str(result)
# Test case 8: Case-insensitive header matching (RFC 7230 / RFC 9110)
litellm.extra_spend_tag_headers = ["x-session-id", "X-Organization-ID"]
result = StandardLoggingPayloadSetup._get_extra_header_tags(
proxy_server_request={
"headers": {
"X-Session-Id": "sess_123",
"x-organization-id": "org_456",
}
}
)
assert result is not None
assert len(result) == 2
assert "x-session-id: sess_123" in result
assert "X-Organization-ID: org_456" in result
finally:
# Restore original value
if original_extra_headers is not None: