Spaces:
Running
Running
fix: add X-Accel-Buffering header to fix ERR_HTTP2_PROTOCOL_ERROR on HF Spaces SSE stream
Browse files- src/api/routes/rag.py +11 -1
src/api/routes/rag.py
CHANGED
|
@@ -86,9 +86,19 @@ async def chat_with_rag_stream(
|
|
| 86 |
|
| 87 |
user_id = current_user.id if current_user else None
|
| 88 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 89 |
return StreamingResponse(
|
| 90 |
router_use_case.execute_stream(request, is_guest=(current_user is None), user_id=user_id),
|
| 91 |
-
media_type="text/event-stream"
|
|
|
|
| 92 |
)
|
| 93 |
except Exception as e:
|
| 94 |
raise HTTPException(status_code=500, detail=str(e))
|
|
|
|
| 86 |
|
| 87 |
user_id = current_user.id if current_user else None
|
| 88 |
|
| 89 |
+
# SSE headers: X-Accel-Buffering: no is critical for HF Spaces nginx
|
| 90 |
+
# to disable proxy buffering which causes ERR_HTTP2_PROTOCOL_ERROR
|
| 91 |
+
headers = {
|
| 92 |
+
"X-Accel-Buffering": "no",
|
| 93 |
+
"Cache-Control": "no-cache, no-transform",
|
| 94 |
+
"Connection": "keep-alive",
|
| 95 |
+
"Transfer-Encoding": "chunked",
|
| 96 |
+
}
|
| 97 |
+
|
| 98 |
return StreamingResponse(
|
| 99 |
router_use_case.execute_stream(request, is_guest=(current_user is None), user_id=user_id),
|
| 100 |
+
media_type="text/event-stream",
|
| 101 |
+
headers=headers,
|
| 102 |
)
|
| 103 |
except Exception as e:
|
| 104 |
raise HTTPException(status_code=500, detail=str(e))
|