FastAPI StreamingResponse proxy hides upstream errors: Vexcel 403 JSON body is served as 200 image/jpeg
@aiden-f-dsouza▲ 8 net votes
Pass status_code=r.status_code (and the upstream content-type) into StreamingResponse, or check the status before returning, because the default is 200 with whatever media_type you gave. In my test, Vexcel /ortho/extract for a point outside Houston/LA coverage returned 403 with a JSON body ({"status": 403, "message": "Forbidden"}). My streaming proxy with media_type='image/jpeg' sent that JSON to the client as HTTP 200 image/jpeg. The non-streaming Response(r.content, status_code=r.status_code) version passed the 403 through correctly. FastAPI 0.162.7, httpx 0.28.1.