Harden HTML5 SSE headers
This commit is contained in:
@@ -1711,7 +1711,7 @@ async def html5_operations_events(
|
||||
return StreamingResponse(
|
||||
stream_operations(),
|
||||
media_type="text/event-stream",
|
||||
headers={"Cache-Control": "no-cache", "X-Accel-Buffering": "no"},
|
||||
headers=_html5_sse_headers(),
|
||||
)
|
||||
|
||||
|
||||
@@ -1777,7 +1777,7 @@ async def html5_project_events(project_id: str, once: bool = False) -> Streaming
|
||||
return StreamingResponse(
|
||||
stream_status(),
|
||||
media_type="text/event-stream",
|
||||
headers={"Cache-Control": "no-cache", "X-Accel-Buffering": "no"},
|
||||
headers=_html5_sse_headers(),
|
||||
)
|
||||
|
||||
|
||||
@@ -2103,7 +2103,7 @@ async def html5_project_setup_events(project_id: str, once: bool = False) -> Str
|
||||
return StreamingResponse(
|
||||
stream_setup(),
|
||||
media_type="text/event-stream",
|
||||
headers={"Cache-Control": "no-cache", "X-Accel-Buffering": "no"},
|
||||
headers=_html5_sse_headers(),
|
||||
)
|
||||
|
||||
|
||||
@@ -8509,6 +8509,14 @@ def _html5_sse_event(event: str, fragment: str) -> str:
|
||||
return f"event: {event}\nretry: 5000\n{data}\n\n"
|
||||
|
||||
|
||||
def _html5_sse_headers() -> dict[str, str]:
|
||||
return {
|
||||
"Cache-Control": "no-cache, no-transform",
|
||||
"Connection": "keep-alive",
|
||||
"X-Accel-Buffering": "no",
|
||||
}
|
||||
|
||||
|
||||
def _html5_sse_if_changed(last_fragments: dict[str, str], event: str, fragment: str):
|
||||
if last_fragments.get(event) == fragment:
|
||||
return
|
||||
|
||||
Reference in New Issue
Block a user