Skip to content
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

Fix issue with FastAPI mounts. #1183

Merged
merged 8 commits into from
Feb 14, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 2 additions & 3 deletions integration_tests/fastapi_mount_test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,5 @@ until curl --fail --silent "$URL" > /dev/null; do
done


curl --fail --silent "http://localhost:$PORT/lilac_sub/api/v1/tasks/"

curl --fail --silent "http://localhost:$PORT/lilac_sub/"
curl --fail --silent "http://localhost:$PORT/lilac_sub/api/v1/tasks/" > /dev/null
curl --fail --silent "http://localhost:$PORT/lilac_sub/" --max-redirs 0 > /dev/null
6 changes: 5 additions & 1 deletion lilac/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,11 @@ async def __call__(self, scope: Scope, receive: Receive, send: Send) -> None:
url = URL(scope=scope).path
root_path = scope.get('root_path') or ''
ends_with_slash = (
url.endswith('/') and url != '/' and root_path and not url.startswith(root_path + '/api')
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can we make this a unit test to enumerate the kinds of URLs that this does/doesn't accept?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

url.endswith('/')
and url != '/'
and root_path
and url != f'{root_path}/'
and not url.startswith(root_path + '/api')
)

if scope['type'] == 'http' and ends_with_slash:
Expand Down
Loading