mirror of
https://github.com/BerriAI/litellm.git
synced 2026-09-05 08:07:05 +00:00
* wip * refactor(tests): move sdk function tracing into rust python harness * dead code * fix: handle harness keyboard interrupts * refactor(tests): deduplicate rust python harness helpers * fix(harness): expose validated strategy choices * wip * refactor(harness): let strategies own parity reports * docs(harness): update strategy structure * refactor(harness): localize strategy report views * wip * fix(harness): satisfy mapping runner type checks * fix(harness): clarify trace parity output * wip * fix(harness): clarify unit mapping report * fix(harness): finalize trace parity contracts * refactor(harness): structure parity contracts * feat: derive unit test mapping from traces * feat(harness): map rstest test families * feat(ocr): port Azure document intelligence tests * feat(harness): enforce complete unit mappings * feat(ocr): add reducto core transforms * feat(harness): classify host-only unit tests * fix(ocr): complete Rust provider plumbing * fix(harness): reuse OCR parity workers
75 lines
2.2 KiB
Python
75 lines
2.2 KiB
Python
from __future__ import annotations
|
|
|
|
from collections.abc import Iterable
|
|
from typing import Final
|
|
from urllib.parse import urlsplit, urlunsplit
|
|
|
|
PARITY_PROVIDER_HOST: Final = "parity-provider.invalid"
|
|
|
|
HOP_BY_HOP_HEADERS: Final[frozenset[str]] = frozenset(
|
|
{
|
|
"connection",
|
|
"keep-alive",
|
|
"proxy-authenticate",
|
|
"proxy-authorization",
|
|
"te",
|
|
"trailer",
|
|
"trailers",
|
|
"transfer-encoding",
|
|
"upgrade",
|
|
}
|
|
)
|
|
|
|
REQUEST_DROPPED_HEADERS: Final[frozenset[str]] = HOP_BY_HOP_HEADERS | {
|
|
"host",
|
|
"content-length",
|
|
"accept-encoding",
|
|
}
|
|
|
|
RESPONSE_DROPPED_HEADERS: Final[frozenset[str]] = HOP_BY_HOP_HEADERS | {
|
|
"content-encoding",
|
|
"content-length",
|
|
"set-cookie",
|
|
}
|
|
|
|
|
|
def connection_header_names(headers: Iterable[tuple[str, str]]) -> frozenset[str]:
|
|
return frozenset(
|
|
token.strip().lower()
|
|
for name, value in headers
|
|
if name.lower() == "connection"
|
|
for token in value.split(",")
|
|
if token.strip()
|
|
)
|
|
|
|
|
|
def dropped_request_headers(headers: Iterable[tuple[str, str]]) -> frozenset[str]:
|
|
materialized: Final = tuple(headers)
|
|
return REQUEST_DROPPED_HEADERS | connection_header_names(materialized)
|
|
|
|
|
|
def dropped_response_headers(headers: Iterable[tuple[str, str]]) -> frozenset[str]:
|
|
materialized: Final = tuple(headers)
|
|
return RESPONSE_DROPPED_HEADERS | connection_header_names(materialized)
|
|
|
|
|
|
def is_streaming_response(content_type: str) -> bool:
|
|
return "text/event-stream" in content_type.lower()
|
|
|
|
|
|
def normalized_response_header(name: str, value: str) -> str:
|
|
if name.lower() not in {"location", "operation-location"}:
|
|
return value
|
|
parsed: Final = urlsplit(value)
|
|
if not parsed.netloc:
|
|
return value
|
|
return urlunsplit(("http", PARITY_PROVIDER_HOST, parsed.path, parsed.query, parsed.fragment))
|
|
|
|
|
|
def local_response_header(name: str, value: str, provider_url: str) -> str:
|
|
if name.lower() not in {"location", "operation-location"}:
|
|
return value
|
|
parsed: Final = urlsplit(value)
|
|
if parsed.hostname != PARITY_PROVIDER_HOST:
|
|
return value
|
|
return f"{provider_url}{parsed.path}{'?' + parsed.query if parsed.query else ''}"
|