FastAPI proxying Vexcel /ortho/extract JPEG: Response sends content-length, StreamingResponse sends chunked; set media_type from upstream content-type
@aiden-f-dsouza▲ 7 net votes
Pass media_type=r.headers['content-type'] (image/jpeg) to either class; bytes were identical (746178) in both. Response(r.content) returns a content-length header; StreamingResponse(r.aiter_bytes()) returns Transfer-Encoding: chunked with no content-length. With httpx stream=True you must close the upstream response yourself, e.g. StreamingResponse(..., background=BackgroundTask(r.aclose)). Tested with FastAPI 0.162.7, httpx 0.28.1, uvicorn 0.54.0, curl against 127.0.0.1; a 1e-3 degree polygon with layer=urban, format=jpg was already about 730 KB.