Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Properly implement AsgiRequest._stream #1171

Closed
dav20011 opened this issue Oct 16, 2018 · 3 comments
Closed

Properly implement AsgiRequest._stream #1171

dav20011 opened this issue Oct 16, 2018 · 3 comments

Comments

@dav20011
Copy link

dav20011 commented Oct 16, 2018

Django requests only contain a stream for the request body and lazy load the request.body property if needed. This is very intuitive because you can handle tasks like a file upload without loading the entire file into the memory while keeping the possibility of easily accessing the request body.

AsgiRequests on the other hand load the entire body before the execution of the view and only offer a fake stream. Looking at this code, it seems perfectly doable to handle this exactly like Django does by default. There actually is a TODO for this feature in the code, but I think it was forgotten.

channels/channels/http.py

Lines 119 to 123 in 9c59938

# TODO: chunked bodies
self._body = body
assert isinstance(self._body, bytes), "Body is not bytes"
# Add a stream-a-like for the body
self._stream = BytesIO(self._body)

@andrewgodwin
Copy link
Member

It was not forgotten, just not implemented yet, since it's a bit trickier to stream this successfully. It should, however, be implemented as you suggest, so I'll leave this open as an enhancement (as it would improve memory efficiency).

@blueyed
Copy link
Contributor

blueyed commented May 6, 2019

Duplicate of #1001 ?

@carltongibson
Copy link
Member

Closing as-per #1001: this'll be part of Django now.

@carltongibson carltongibson closed this as not planned Won't fix, can't repro, duplicate, stale Jul 25, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants