fix: Add standard Server-Sent Events headers to StreamingResponse for improved client compatibility.

rest-api
MrWaradana 1 month ago
parent 50153ef230
commit 27954e3a17

@ -128,7 +128,14 @@ async def simulate_equipment(db_session: DbSession, assetnum: str):
combined = {'prediksi': prediksi, 'hasil_eac': hasil_eac}
yield f"data: {json.dumps({'status':'done','message':f'Simulation for {assetnum} completed successfully','data':combined})}\n\n"
return StreamingResponse(event_generator(), media_type='text/event-stream')
headers = {
"Content-Type": "text/event-stream",
"Cache-Control": "no-cache, no-transform",
"Connection": "keep-alive",
"X-Content-Type-Options": "nosniff",
"Content-Encoding": "none"
}
return StreamingResponse(event_generator(), media_type='text/event-stream', headers=headers)
@router.get("/simulate-all")
@ -171,7 +178,14 @@ async def simulate_all_equipment(db_session: DbSession):
yield f"data: {json.dumps({'status':'done', 'message':f'All simulations completed. Success: {success_count}, Errors: {error_count}'})}\\n\\n"
return StreamingResponse(event_generator(), media_type='text/event-stream')
headers = {
"Content-Type": "text/event-stream",
"Cache-Control": "no-cache, no-transform",
"Connection": "keep-alive",
"X-Content-Type-Options": "nosniff",
"Content-Encoding": "none"
}
return StreamingResponse(event_generator(), media_type='text/event-stream', headers=headers)
@router.get(
"/count-remaining-life",

Loading…
Cancel
Save