-
Notifications
You must be signed in to change notification settings - Fork 154
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
Demonstration of ASGI support. #181
Conversation
Tested this with an example using uvicorn as well: https://github.com/erm/uvicorn-examples/tree/master/whitenoise |
Thanks Tom, this is really helpful. I reckon we can get around the compatibility issue reasonably easily. If we change the responder API to return a file path and a seek offset rather than the file handle then the caller can handle that using sync or async code as it wishes. At least, that's the first thing that occurs to me; I haven't thought all the implications yet, or whether there are better alternatives. But I'm pretty confident it's solvable in any case. |
That's a really nice idea, yup. Then it only ends up being I guess that until you want to drop Python 2, it might make sense for any ASGI variant to be a separate package, that's just the small extra shim on top? |
e8510fe
to
6775fae
Compare
@tomchristie I was trying this on my local but at this line https://github.com/evansd/whitenoise/pull/181/files#diff-ffc8dfee817831216f12835223bcad04R252 I am getting |
fcaf91a
to
4d8a3ab
Compare
range_header = request_headers.get('HTTP_RANGE') | ||
if range_header: | ||
try: | ||
return await self.get_range_response(range_header, headers, file_handle) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should be get_range_response_async
return await self.get_range_response(range_header, headers, file_handle) | |
return await self.get_range_response_async(range_header, headers, file_handle) |
I'm going to close this off, since I'm not particularly planning on progressing it myself. |
Fair enough! Thanks for the work you've put into this and sorry I didn't end up able to progress it either. Whitenoise is obviously going to have to go async at some point, but it's just a question of finding the time 😃 |
Yeah, s'all good. |
I am having trouble understanding what this solves. Is it to allow ASGI apps to serve compressed files? WhiteNoise appears to work just fine with daphne + ASGI as long as the middleware is added; wrapping the ASGI app is seemingly unnecessary. However, I am using |
This pull request is intended as a demonstration of the scope of changes needed to add ASGI support to WhiteNoise.
Refs #179.
Some notes:
async
andawait
syntax. The codebase won't be 2.7 compatible.aiofiles
package for non-blocking file open and read.sendfile
support. There's not yet any provision for that in the ASGI spec, so there'd need to be some discussion around the right API for adding that as an extension.An example...
example.py
Run using
daphne
...