mirror of
https://github.com/BerriAI/litellm.git
synced 2026-11-04 07:27:51 +00:00
Merge 080145ff81 into 3b8ad37296
This commit is contained in:
commit
53a6ce6ee6
2 changed files with 25 additions and 5 deletions
|
|
@ -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}")
|
||||
|
||||
|
|
|
|||
|
|
@ -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:
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue