question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Expose ASGI scope on Request object

See original GitHub issue

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 a scope attribute which is the current ASGIScope

Additional context Presently I’m working around this by accessing request.app._asgi_app.transport.scope

Issue Analytics

  • State:closed
  • Created a year ago
  • Comments:11 (8 by maintainers)

github_iconTop GitHub Comments

1reaction
ahopkinscommented, Apr 18, 2022

Actually… as I think about it more, I do not think that we even need to set it on the Request object at all. You should have access to it (I believe):

request.transport.scope

Therefore, it is just a matter of returning that in the property and making sure that you are in ASGI.

1reaction
ahopkinscommented, Mar 28, 2022

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.

Read more comments on GitHub >

github_iconTop Results From Across the Web

ASGI middleware support · Issue #191 - GitHub
This makes perfect sense. I'm already exposing the send and receive functions as asgi.send and asgi.receive , so we can add asgi.scope ....
Read more >
Requests - Starlette
Starlette includes a Request class that gives you a nicer interface onto the incoming request, rather than accessing the ASGI scope and receive...
Read more >
Working with HTTP requests in ASGI - Encode
The first thing that occurs in any ASGI application is that it is instantiated with a “scope” dictionary, that provides some initial information...
Read more >
How to allow a Channels consumer to access session ...
What I want to do now is to create a WebsocketConsumer and access the session from within. I have enabled SessionMiddlewareStack. The problem...
Read more >
ASGI Request & Response — Falcon 3.1.1 documentation
Represents a client's HTTP request. Request is not meant to be instantiated directly by responders. scope (dict) – ASGI HTTP connection scope passed...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found