Repository navigation
Conversation
Since collection and item identifiers became `path` converters (geopython#1267), a trailing slash is captured as part of an identifier instead of being ignored as `strict_slashes = False` intends: `/collections/foo/items/` is routed to the collection endpoint with the collection `foo/items/`, as are `/queryables/`, `/facets/` and `/collections/foo/`. The lookup of that unknown collection then raised IndexError, so these URLs, which worked before, now return 500. - Strip a trailing slash from the request path before routing, so every URL behaves the same with or without it. - collection(): answer 404 for an unknown collection instead of failing on an empty query result (also when there is no trailing slash).
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes a regression from #1267.
Problem
Since collection and item identifiers became
pathconverters in #1267, a trailing slash ends up inside the identifier instead of being ignored, which is whatAPP.url_map.strict_slashes = Falsemeans it to do:/collections/metadata:main/items/items, 200collectionwith idmetadata:main/items/, 500/collections/<id>/queryables/queryablescollectionwith id<id>/queryables/, 500/collections/<id>/collectioncollectionwith id<id>//collections/<id>/items/<item>/itemitemwith id<item>/The 500 comes from
collection():self.repository.query_ids([collection])[0]raisesIndexErrorfor an identifier that doesn't exist. That also turns any unknown collection (/collections/does-not-exist) into a 500 rather than a 404, with or without a slash.Change
wsgi_flask.py: a small WSGI middleware strips a trailing slash fromPATH_INFObefore routing. Every route then behaves the same with or without the slash, as it did before Support STAC collection identifiers containing path separators #1267. The root path/is left alone.records.pycollection(): returns 404collection not foundfor an unknown collection, the same response shape asitem not found.Tests
test_trailing_slash_routes_like_no_slash_and_unknown_collection_is_404(Flask test client, so the middleware is exercised). It checks that/collections/metadata:main/items,/queryables,/collections/metadata:main,/collections,/stac/collectionsand/give the same response with and without a trailing slash (ignoringtimeStamp), and that an unknown collection returns 404. It fails onmasterwithout this change, at/collections/metadata:main/items/.not harvesting and not distributedsearch and not pubsub): 410 passed.