Replace httpx and httpx-sse with httpx2 (#2972)
Co-authored-by: Max Isbey <224885523+maxisbey@users.noreply.github.com>
This commit is contained in:
parent
1216c53693
commit
2713b53b12
1 changed files with 1029 additions and 948 deletions
|
|
@ -2,7 +2,7 @@
|
|||
|
||||
from collections.abc import Generator
|
||||
|
||||
import httpx
|
||||
import httpx2
|
||||
|
||||
from mcp.client import Client
|
||||
from stories._harness import Target, run_client
|
||||
|
|
@ -10,22 +10,22 @@ from stories._harness import Target, run_client
|
|||
from .server import DEMO_TOKEN, REQUIRED_SCOPE
|
||||
|
||||
|
||||
class StaticBearerAuth(httpx.Auth):
|
||||
"""``httpx.Auth`` that attaches a fixed ``Authorization: Bearer <token>`` to every request."""
|
||||
class StaticBearerAuth(httpx2.Auth):
|
||||
"""``httpx2.Auth`` that attaches a fixed ``Authorization: Bearer <token>`` to every request."""
|
||||
|
||||
def __init__(self, token: str) -> None:
|
||||
self.token = token
|
||||
|
||||
def auth_flow(self, request: httpx.Request) -> Generator[httpx.Request, httpx.Response, None]:
|
||||
def auth_flow(self, request: httpx2.Request) -> Generator[httpx2.Request, httpx2.Response, None]:
|
||||
request.headers["Authorization"] = f"Bearer {self.token}"
|
||||
yield request
|
||||
|
||||
|
||||
def build_auth(_http: httpx.AsyncClient) -> httpx.Auth:
|
||||
"""The demo bearer token as an ``httpx.Auth``.
|
||||
def build_auth(_http: httpx2.AsyncClient) -> httpx2.Auth:
|
||||
"""The demo bearer token as an ``httpx2.Auth``.
|
||||
|
||||
``Client(url, auth=...)`` doesn't exist yet, so the harness threads this onto the underlying
|
||||
``httpx.AsyncClient`` and the target ``main`` receives is already routed through it.
|
||||
``httpx2.AsyncClient`` and the target ``main`` receives is already routed through it.
|
||||
"""
|
||||
return StaticBearerAuth(DEMO_TOKEN)
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue