-
Notifications
You must be signed in to change notification settings - Fork 2
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
PB-796: handle paths without trailing slash without redirection. #440
Conversation
b125272
to
a810b67
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nice solution!
self.logger.error( | ||
'Not redirecting path that already ends with a slash: %s: %s', | ||
request.path_info, | ||
request | ||
) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
so this is a case that should never happen, right?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It should not. But if it does I think it's better to return gracefully and log the error than to get stuck in an infinite loop or to return 500 to the user.
API Gateway v1 strips trailing slashes from the request paths. We have a few endpoints that use trailing slashes. Specifically: - /api/stac/v1/ - /api/stac/v0.9/ - /api/stac/admin/* Django's CommonMiddleware already has a feature to redirect URLs without trailing slash to their "slashed" equivalent when they exist. When combined with API Gateway v1 this causes a redirection loop. This change introduces CommonMiddlewareWithInternalRedirect which handles the redirection internally to serve the query like if it had hit the "slashed" page directly. It also updates the test to verify both endpoints work correctly. Based on discussion in https://ltwiki.adr.admin.ch:8443/display/~adrien.kunysz@swisstopo.ch/STAC+API+trailing+slash+inconsistency
453748f
to
4eda290
Compare
In #440 we added CommonMiddlewareWithInternalRedirect to respond to URLs that don't end with a trailing slash without user-visible redirection. This was primarily done to handle a limitation of AWS API Gateway v1. We eventually decided to use API Gateway v2 which does not have this limitation. Hence, we remove this code that is not useful and update the tests accordingly. This is basically a revert of #440 although we keep some of the test refactoring/improvements.
API Gateway v1 strips trailing slashes from the request paths. We have a few endpoints that use trailing slashes. Specifically:
/api/stac/v1/
/api/stac/v0.9/
/api/stac/admin/*
Django's CommonMiddleware already has a feature to redirect URLs without trailing slash to their "slashed" equivalent when they exist. When combined with API Gateway v1 this causes a redirection loop.
This change introduces CommonMiddlewareWithInternalRedirect which handles the redirection internally to serve the query like if it had hit the "slashed" page directly.
It also updates the test to verify both endpoints work correctly.
Based on discussion in https://ltwiki.adr.admin.ch:8443/display/~adrien.kunysz@swisstopo.ch/STAC+API+trailing+slash+inconsistency