fix: add SSE streaming proxy and robust make try startup
The SSE proxy was buffering the entire response body with a 30s read timeout, causing 504s on the OpenCode /global/event stream. Add a streaming path that detects SSE requests (by Accept header or /event path) and returns a StreamingResponse with no read timeout. Also fix the make try target to poll the health endpoint for Docker readiness and wait for the container to reach running status before opening the browser.
This commit is contained in:
@@ -159,6 +159,24 @@ async def make_http_request(method: str, url: str, **kwargs) -> httpx.Response:
|
||||
return await client.request(method, url, **kwargs)
|
||||
|
||||
|
||||
@asynccontextmanager
|
||||
async def stream_http_request(method: str, url: str, **kwargs):
|
||||
"""Stream an HTTP response using a dedicated client with no read timeout.
|
||||
|
||||
Yields an httpx.Response whose body has NOT been read -- caller must
|
||||
iterate over ``response.aiter_bytes()`` / ``aiter_lines()`` etc.
|
||||
|
||||
A separate AsyncClient is used (not the pool) because httpx's
|
||||
``stream()`` keeps the connection checked-out for the lifetime of the
|
||||
context manager, and SSE streams are effectively infinite. Using a
|
||||
short-lived client avoids starving the pool.
|
||||
"""
|
||||
timeout = httpx.Timeout(connect=10.0, read=None, write=10.0, pool=5.0)
|
||||
async with httpx.AsyncClient(timeout=timeout, follow_redirects=False) as client:
|
||||
async with client.stream(method, url, **kwargs) as response:
|
||||
yield response
|
||||
|
||||
|
||||
async def get_connection_pool_stats() -> Dict[str, Any]:
|
||||
"""Get connection pool statistics."""
|
||||
return await _http_pool.get_pool_stats()
|
||||
|
||||
Reference in New Issue
Block a user