mirror of
https://github.com/BerriAI/litellm.git
synced 2026-09-19 00:01:29 +00:00
fix(memory): preserve client network context for internal calls
This commit is contained in:
parent
1e7963abba
commit
ada17a3430
2 changed files with 11 additions and 3 deletions
|
|
@ -192,13 +192,15 @@ async def prepare_gateway_memory(
|
|||
try:
|
||||
# Dispatch in process through the existing authenticated endpoint. No
|
||||
# network client, TLS context, or connection pool is created here.
|
||||
async with httpx.ASGITransport(app=app) as transport:
|
||||
async with httpx.ASGITransport(
|
||||
app=app, client=request.client or ("127.0.0.1", 0), root_path=request.scope.get("root_path", "")
|
||||
) as transport:
|
||||
|
||||
async def dispatch_round(body: Mapping[str, object]) -> httpx.Response:
|
||||
result: Final = await transport.handle_async_request(
|
||||
httpx.Request(
|
||||
"POST",
|
||||
"http://litellm-memory" + request.url.path,
|
||||
str(request.url),
|
||||
json=body,
|
||||
headers=headers,
|
||||
params=request.query_params,
|
||||
|
|
|
|||
|
|
@ -321,6 +321,9 @@ async def test_gateway_rounds_keep_separate_limiter_contexts_and_original_client
|
|||
|
||||
@provider.post("/v1/messages")
|
||||
async def model(request: Request):
|
||||
assert request.client is not None and request.client.host == "203.0.113.7"
|
||||
assert request.url.scheme == "https" and request.headers["host"] == "gateway.example"
|
||||
assert request.query_params["api-version"] == "test-version"
|
||||
body = await request.json()
|
||||
call_id = body["litellm_call_id"]
|
||||
stash = claim_request_stash_for_data(body)
|
||||
|
|
@ -345,7 +348,10 @@ async def test_gateway_rounds_keep_separate_limiter_contexts_and_original_client
|
|||
{
|
||||
"type": "http",
|
||||
"path": "/v1/messages",
|
||||
"query_string": b"",
|
||||
"scheme": "https",
|
||||
"server": ("gateway.example", 443),
|
||||
"client": ("203.0.113.7", 41231),
|
||||
"query_string": b"api-version=test-version",
|
||||
"headers": [(b"authorization", b"Bearer test"), (b"idempotency-key", b"visible-only")],
|
||||
}
|
||||
)
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue