Use zero copy to send file if can#1288
Conversation
| ) | ||
| if self.send_header_only: | ||
| await send({"type": "http.response.body", "body": b"", "more_body": False}) | ||
| elif "http.response.zerocopysend" in scope["extensions"]: # pragma: no cover |
There was a problem hiding this comment.
I'm not sure how to test it. It seems too simple to just test if the result it returns is a dictionary. Do you have any suggestions?
|
By the way, should we use range and if-range header? I saw it in someones toolkit |
Co-authored-by: Marcelo Trylesinski <[email protected]>
Co-authored-by: Marcelo Trylesinski <[email protected]>
|
Than you for pointing out. But is that means |
|
In addition, # main.py
from starlette.applications import Starlette
from starlette.routing import Route
from baize.asgi import FileResponse
async def homepage(request):
return FileResponse("./main.py")
routes = [
Route("/", endpoint=homepage)
]
app = Starlette(debug=True, routes=routes) |
Yes. These parameters need to be specified. |
Great feature! |
Simply because they support the ASGI3 protocol. I was fascinated by this design in Starlette, so I implemented a similar part for WSGI. |
| } | ||
| ) | ||
| finally: | ||
| await anyio.to_thread.run_sync(os.close, fd) |
There was a problem hiding this comment.
I'm... not comfortable with this.
Not at all obvious to me how the open/zerocopesend/close would interact.
I've got a bit of a preference here that we close this off for now as a "feature pause" until we're sufficiently on top of all existing issues that we can thoroughly review this.
https://asgi.readthedocs.io/en/latest/extensions.html#zero-copy-send