Skip to content

OARec/STAC: route trailing-slash URLs as before #1267 - #1272

Open
epifanio wants to merge 1 commit into
geopython:masterfrom
epifanio:fix-trailing-slash-routes
Open

epifanio wants to merge 1 commit into
geopython:masterfrom
epifanio:fix-trailing-slash-routes

Conversation

@epifanio

Copy link
Copy Markdown
Contributor

Fixes a regression from #1267.

Problem

Since collection and item identifiers became path converters in #1267, a trailing slash ends up inside the identifier instead of being ignored, which is what APP.url_map.strict_slashes = False means it to do:

URL before #1267 now
/collections/metadata:main/items/ items, 200 collection with id metadata:main/items/, 500
/collections/<id>/queryables/ queryables collection with id <id>/queryables/, 500
/collections/<id>/ collection collection with id <id>/
/collections/<id>/items/<item>/ item item with id <item>/

The 500 comes from collection(): self.repository.query_ids([collection])[0] raises IndexError for 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 from PATH_INFO before 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.py collection(): returns 404 collection not found for an unknown collection, the same response shape as item not found.

Tests

  • New 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/collections and / give the same response with and without a trailing slash (ignoring timeStamp), and that an unknown collection returns 404. It fails on master without this change, at /collections/metadata:main/items/.
  • Unit: 160 passed. Functional (not harvesting and not distributedsearch and not pubsub): 410 passed.

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).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant