get_route_path uses regex to remove the prefix #2541
Unanswered
sk-
asked this question in
Potential Issue
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
The logic to get the route path is using regex to remove the prefix. This had two potential issues. On one hand, this could produce unexpected results in case of using regex special characters like
.
,. On the other hand regexes are slow and could be replaced by removeprefix in Python 3.9+, and with a simple slicing in Python 3.8.starlette/starlette/_utils.py
Lines 96 to 99 in 554f368
I checked PR #2400 which introduced this function, and also https://fastapi.tiangolo.com/advanced/behind-a-proxy/#setting-the-root_path-in-the-fastapi-app, but nowhere it's mentioned that the
root_path
could be a regex.I have already tested the change and there is some small improvement (~1-2%) in the number of RPS.
Beta Was this translation helpful? Give feedback.
All reactions