Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions openvidia/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,17 @@ def httpx_timeout_kwargs() -> dict[str, float]:
UPSTREAM_CHAT = UPSTREAM_BASE + "chat/completions"


def upstream_http2() -> bool:
"""Whether upstream requests share one multiplexed HTTP/2 connection.

With HTTP/2 a single GOAWAY from the upstream (``ConnectionTerminated``)
kills every in-flight stream at once, and a client mid-stream sees a
broken event. ``OPENVIDIA_HTTP2=0`` gives each request its own HTTP/1.1
connection, so a closed connection costs one stream, not all of them.
"""
return os.environ.get("OPENVIDIA_HTTP2", "1").strip().lower() not in ("0", "false", "no", "off")


def outbound_proxy() -> str | None:
"""Return outbound HTTP/SOCKS5 proxy URL for upstream requests.

Expand Down
2 changes: 1 addition & 1 deletion openvidia/proxy_app.py
Original file line number Diff line number Diff line change
Expand Up @@ -313,7 +313,7 @@ def create_app(state: ProxyState, web_dir: Path | None = None) -> FastAPI:
limits = httpx.Limits(max_keepalive_connections=100, max_connections=200, keepalive_expiry=30.0)
proxy_url = config.outbound_proxy()
client = httpx.AsyncClient(
http2=True,
http2=config.upstream_http2(),
proxy=proxy_url if proxy_url else None,
limits=limits,
timeout=httpx.Timeout(**config.httpx_timeout_kwargs()),
Expand Down
17 changes: 17 additions & 0 deletions tests/test_upstream_http2.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
from openvidia import config


def test_http2_is_the_default(monkeypatch):
monkeypatch.delenv("OPENVIDIA_HTTP2", raising=False)
assert config.upstream_http2() is True


def test_http2_can_be_switched_off(monkeypatch):
for value in ("0", "false", "no", "off", " OFF "):
monkeypatch.setenv("OPENVIDIA_HTTP2", value)
assert config.upstream_http2() is False


def test_any_other_value_keeps_http2(monkeypatch):
monkeypatch.setenv("OPENVIDIA_HTTP2", "1")
assert config.upstream_http2() is True
Loading