-
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
How should servers utilise root_path
#229
Comments
ASGI documents We ran into this while working on sans-IO / ASGI support in Werkzeug pallets/werkzeug#2005 (comment). |
This seems to be the relevant bug in Daphne: django/daphne#125. I couldn't find one for Uvicorn. |
Interesting, we had one user complaining recently it wasn't working as
expected, encode/uvicorn#937
I must admit I rapidly tested against daphne and hypercorn, and as same
routes were served the same way as in uvicorn I maybe diagnosed too fast
this wasn't a problem, but seeing this I'm not sure about it now, not
familiar enough with the SCRIPT_NAME behavior.
I always thought root_path was meant to be used with a reverse proxy
…On Wed, Jan 20, 2021, 6:10 PM David Lord ***@***.***> wrote:
This seems to be the relevant bug in Daphne: django/daphne#125
<django/daphne#125>. I couldn't find one for
Uvicorn.
—
You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub
<#229 (comment)>, or
unsubscribe
<https://github.com/notifications/unsubscribe-auth/AAINSPQCMARL2DN57LRCWY3S24FAFANCNFSM4WK62A7A>
.
|
There are various ways to manage it, but ultimately the WSGI server and/or app needs to know where it's mounted and adjust |
I've altered Hypercorn to act as WSGI does, see this commit |
See also #230. |
The intention of the spec is thus:
(this is made slightly clearer at the bottom in https://asgi.readthedocs.io/en/latest/specs/www.html#wsgi-compatibility) It was my intention that frameworks doing URL routing on just the "local" section remove |
I see. Then the spec needs to clarify that I sort of understand this, since it makes building URLs work the same as matching URLs. But this is going to make extracting behavior in Werkzeug to work with both WSGI and ASGI trickier, not sure exactly what the answer is yet for us. It also seems to be causing misunderstandings based on the linked issues. |
The compatibility section of the spec currently says:
Now that you've clarified your intention, I see that it means "can be derived by stripping |
I guess my next question is what the point of |
Well, the point of having it is twofold:
I agree the spec could be a lot more clear - happy to improve the language there. |
This now makes sense to me, I'll close. |
…spec Before this change, the dispatcher middleware didn't do anything with 'root_path'. It did, however, modify 'path'. The problem with this behavior, is that the child ASGI app has no way to determine what its prefix it. And if it can't determine its prefix, it doesn't know how to construct URLs. The ASGI spec isn't super clear on the expected behavior. However, some resources to review are: * https://asgi.readthedocs.io/en/latest/specs/www.html#wsgi-compatibility * encode/starlette#2400 * django/asgiref#229 Based on the above, I believe that the correct behavior is that "root_path" should be updated by the dispatcher middleware but that "path" should not be modified. In addition to the above change, I also updated the tests. And I also added a new test case where the dispatcher middleware is nested inside of itself.
root_path
is often considered equivalent to WSGI'sSCRIPT_NAME
, yet usage ofroot_path
by servers differs in that WSGI servers seem to split out theSCRIPT_NAME
from thePATH_INFO
whereas ASGI servers (Daphne, Hypercorn, Uvicorn) do not,I find (for all 3 ASGI servers, with daphne shown),
whereas I think the scope should be,
I.e. the server should 404 if the request target does not start with the
root_path
, and if it does remove it from thepath
, but keep it in theraw_path
. Are the current ASGI servers correct, or does the ASGI spec need to be clearer about this?The text was updated successfully, but these errors were encountered: