-
Notifications
You must be signed in to change notification settings - Fork 213
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
About scope[path]
and scope[root_path]
#424
Comments
Line 60 in d95e378
asgiref itself seems to consider path and PATH_INFO to be completely equivalent. But if it wants to comply with ASGI's current specification, it should be modified as in this PR - remove https://asgi.readthedocs.io/en/latest/specs/www.html#wsgi-compatibility |
Agree 💯, they are considered equal |
I put this in the WSGI compat docs very deliberately:
The WSGI adapter in |
I mean, it seems that most of the existing ASGI-related procedures do not comply with this standard. Do we still need to insist on this? |
Standards are obtained by consensus, not by dictat, so if there's strong consensus on another way of doing it from all the main servers we can change it. |
Okay, let's wait for the other people's opinions. As far as the code I looked up, most people still use exactly the same approach as WSGI. |
Hi @abersheeran no problem with mentioning me, thank you for bringing this up.
I started using Personally, I find natural to think about the "path" as the path from application's perspective, therefore not including the root path, but I don´t have a problem in updating my code to follow the specification. |
Hello all! Just to make sure I'm on the same page, I'm gonna share my understanding of the current state, differences, and the current question. MountingI see that the discussion/difference is in the end mainly about WSGI's I see the discussion/problem and questions are only relevant to "mounting" ASGI apps, where "mounting" refers to putting the ASGI app behind a path prefix in a situation where the app's code doesn't know about this prefix. For example, the app defines a route for WSGIIn WSGI, When the WSGI app wants to check which of its own route/path handlers should handle that request, it checks the value of The WSGI app would get the path prefix in ASGIIn ASGI, The ASGI app would receive the path prefix at When the ASGI app needs to find the route/path handler for a request, it would remove the prefix value in the When the ASGI app needs to find the RelevanceNow, this is mainly relevant for things that are mounted behind a proxy, or behind/mounted in another app. For example, say there's a Starlette app at In the current (unmodified) state of the spec, Starlette should send a scope including a The same for a2wsgi (which it already does), e.g. mounting a Flask app inside a FastAPI app, under Moving ForwardEven though it could mean a couple of changes and "work" for all of us, I would consider it better to follow the spec as it is, without changing it, and fix this (small) detail in the tools as a "bug fix". I fear otherwise it could become a scenario of "in version X of SuperASGITool it used the ASGI spec 2.3 as of 2023, but in version Y of SuperASGITool it started following the updated version of the ASGI spec 2.4 updated in 2024". Something very similar happened with OpenAPI and JSON SchemaOpenAPI followed an old version of JSON Schema that didn't include Now the latest OpenAPI follows the latest JSON Schema, and things are much simpler, but still, there are some places that accept the old All that is not terrible, and the difference is very small, but it ends up being somewhat confusing, in particular to users, and requires long text (like this one) explaining all the state of things, what works and what doesn't, when, how, etc. More details about all the ...that's the type of long explanations I would hope we can save our users from. 😅 Starlette was recently using the old behavior, but it was fixed to follow the spec by @Kludex and me in encode/starlette#2352 and encode/starlette#2400. Again, the places that need changing are only those that might be related to "mounting" apps under a path prefix (when that's supported). |
Yes, it is good to follow the rules. However, among the existing codes in the community, only a few frameworks or servers comply with this specification. Personally I think it's better to use exactly the same approach as WSGI. (Although I have made a2wsgi compliant spec) WSGI has been used for more than ten years, and it is really confusing to be similar and different from WSGI in such small details. And this change does not seem to have any good impact. Instead, it makes the framework make more judgments when processing PATH. We should let as few people as possible modify the code, rather than specify a specification that most people don't follow and then say "Hey, your code is wrong" when their users have problems. |
This was one of the few explicit divergences I made from WSGI - along with things like improving the string/bytes separation - and it was because I believed that having a "true" HTTP path was the most helpful thing to have in the In ASGI, direct path manipulation with relative paths works perfectly fine; in WSGI, it does not, and you can easily shoot yourself in the foot. Ideally, in both specifications you are going to work out the third missing piece of info, but I regarded it as more important to have the path right out of the gate for simpler ASGI applications (assuming frameworks will have the relevant 3 lines of code to do URL matching, as they tend to). ASGI itself is now seven years old, so an appeal to how old and fixed something is may not be entirely the right approach! |
FWIW this behaviour was brought into line in the last Daphne and Channels releases too. Django also is compliant. |
Following the ASGI HTTP Connection Scope docs[0], the provided `path` is already the correct value that Django requires. In combination with `root_path`, from which `script_name` is derived, the `path_info` variable is set. It's then redundant to re-calculate `path` from `script_name` and `path_info`. See also, a clarifying discussion on the ASGIref repo[1]. [0]: https://asgi.readthedocs.io/en/latest/specs/www.html#http-connection-scope [1]: django/asgiref#424
Following the ASGI HTTP Connection Scope docs[0], the provided `path` is already the correct value that Django requires. In combination with `root_path`, from which `script_name` is derived, the `path_info` variable is set. It's then redundant to re-calculate `path` from `script_name` and `path_info`. See also, a clarifying discussion on the ASGIref repo[1]. [0]: https://asgi.readthedocs.io/en/latest/specs/www.html#http-connection-scope [1]: django/asgiref#424
Related links:
root_path
#229In the first link, @andrewgodwin stated the differences between root_path and path in WSGI. After Starlette actively followed up, this led to the problem in the second link.
Yes, we can make some changes to make it work again, but the question is what is the existing community implementation?
I searched for the code via GitHub and can view the results via the third link. I noticed that in the first page of results, everyone except hypercorn and starlette treat path as the equivalent of PATH_INFO in WSGI. They get the full path by concatenating root_path and path.
So I think we should modify the specification document so that path is exactly the same as PATH_INFO. Otherwise, this will have a strong impact on the existing implementation of the community.
A polite mention of the author of code in the search results, I hope this doesn't bother you. @Kludex @pgjones @kennethreitz @Goldziher @simonw @RobertoPrevato @long2ice If you have time, could you express some thoughts on this?
The text was updated successfully, but these errors were encountered: