Open Goldziher opened 1 year ago
Update- This appears to be more complex than I assumed. the sendfile
method is not implemented on all loops at all. Furthermore, it requires access to the async transport, which is a low level abstraction defined by the asyncio implementation but not anyio.
PROS: dramatically faster file serving using the operating system. CONS: a lot more complexity and only support on asyncio.
I think we have to do this - but it requires significant efforts to implement. An example of an implementation is in aiohttp
, specifically here: https://github.com/aio-libs/aiohttp/blob/master/aiohttp/web_fileresponse.py#L83
Additional context: https://github.com/aio-libs/aiohttp/blob/master/aiohttp/web_fileresponse.py#L83
specifically here: https://github.com/aio-libs/aiohttp/blob/master/aiohttp/web_fileresponse.py#L83
Additional context: https://github.com/aio-libs/aiohttp/blob/master/aiohttp/web_fileresponse.py#L83
I assume "Additional context:" should be a different link here?
We should use
loop.sendfile
(Introduced in Python 3.7) to send files and fallback to chunking. This is significantly more performant.(edited by @JacobCoffee)