-
-
Notifications
You must be signed in to change notification settings - Fork 935
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
Handling of scope["root_path"]
and scope["path"]
differs from ASGI spec
#1336
Labels
Milestone
Comments
Kludex
added
bug
Something isn't working
refactor
Refactor code
and removed
bug
Something isn't working
labels
Nov 27, 2021
2 tasks
Hello @Kludex 👋 I would be interested to help tackling this issue; if you need a hand, let me know :) |
Take in consideration that I'll need a lot of references to follow on this, and to understand the implications for our users. But yeah, help is appreciated. 🙏 |
frankie567
added a commit
to frankie567/starlette
that referenced
this issue
Jul 22, 2022
1 task
This was referenced Sep 4, 2022
Kludex
pushed a commit
to frankie567/starlette
that referenced
this issue
Sep 11, 2022
maartenbreddels
added a commit
to widgetti/solara
that referenced
this issue
Dec 5, 2023
path now includes root_path so we need a different way to remove it. It seems like route_root_path gives this information. See encode/starlette#2361 encode/starlette#2352 encode/starlette#1336
maartenbreddels
added a commit
to widgetti/solara
that referenced
this issue
Dec 8, 2023
path now includes root_path so we need a different way to remove it. It seems like route_root_path gives this information. See encode/starlette#2361 encode/starlette#2352 encode/starlette#1336
8 tasks
18 tasks
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Labels
Checklist
master
.Describe the bug
Accoring to django/asgiref#229 (comment),
scope["path"]
includes thescope["root_path"]
.So if root_path is
/foo
and request for/foo/bar
has come, the upstream application servers (such as uvicorn) are passingscope["path"] == "/foo/bar" and scope["root_path"] == "/foo"
, which is correct behavior.But starlette does not conform this. It assumes
scope["path"]
is a remainder of strippingscope["root_path"]
from original request path. In this case,scope["path"] == "/bar" and scope["root_path"] == "/foo"
. This ASGI incompatible assumption can be seen here or here and many other places.The following "To reproduce" section shows just one aspect of this wrong assumption.
To reproduce
main.py
as follows.uvicorn main:app --port 8000 --root-path /foo
curl http://localhost:8000/foo/bar
Expected behavior
Receives
Actual behavior
Receives
Some points here are,
scope['path']
does not includescope['root_path']
, which is ASGI incompatible.FooBar
ASGI handler is called. It does not takescope['root_path']
into account when routing.Environment
Additional context
This may be a root cause of this issue in fastapi
Important
The text was updated successfully, but these errors were encountered: