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
Expose ASGI scope on Request object #2417
Comments
That's a good idea, and sounds easy enough that we can probably squeeze that in for the upcoming release. |
You'll probably need to handle the case where the server isn't being run via ASGI and thus there is no |
Just curious, what makes you think this is the case? The built-in Sanic server (TMK) is still the most common deployment method. But, I do agree that ASGI support is an important alternative. |
I can't recall exactly, but I may have skimmed this thread and came away with the wrong idea. |
No, not necessarily. ASGI is very important and I hope will continue to be. But we are not getting rid of the internal server either. Being geared specifically for Sanic it has the benefit of being optimized for performance in ways that ASGI servers cannot be. |
Hi, I would like to take this issue, as my first contribution to the project. |
That sounds reasonable, but then again, you could also make it a I'm not very familiar with Sanic's internals though, so I can't say what the best option would be. |
Yeah, I can do that, but I guess the downside is that currently the Request object is decoupled completely from any ASGI internals, and this change will change that a bit. |
@azimovMichael I would be happy for you to take this on. I see you have been assigned it already. Sorry for my delay, I am just now getting back to my regular schedule after some time off. Instead of altering the instance.request = request_class(
...
)
instance.request.stream = instance
...
instance.request._scope = scope Using |
I would go so far as to do something like this: @property
def scope(self):
if not self._scope:
raise NotImplementedError("...")
return self._scope |
Actually... as I think about it more, I do not think that we even need to set it on the request.transport.scope Therefore, it is just a matter of returning that in the |
Is your feature request related to a problem? Please describe.
I'm trying to write an application framework that works across ASGI compatible server implementations and to do this I'd like to make the ASGI scope available to users. Sanic does not make the scope publicly available though.
Describe the solution you'd like
I'd like the
sanic.request.Request
object to provide ascope
attribute which is the currentASGIScope
Additional context
Presently I'm working around this by accessing
request.app._asgi_app.transport.scope
The text was updated successfully, but these errors were encountered: