Avoid internal server error when no format requested in get_collection_item (#1274)

Previously, request.format was assumed to always be defined when
generating `prev` and `next` links.

This commit changes this by using json as default format. This supports
the use case of curl nicely, but we could also choose e.g. html.

This branch is not yet tested because I didn't manage to find/produce test
data for single items which have next/previous links.

Fixes https://github.com/geopython/pygeoapi/issues/1272
This commit is contained in:
totycro
2023-07-01 15:06:36 +02:00
committed by GitHub
parent 6a871e8591
commit d7b112f62b
+7 -4
View File
@@ -2363,17 +2363,20 @@ class API:
'href': f'{self.get_collections_url()}/{dataset}'
}])
link_request_format = (
request.format if request.format is not None else F_JSON
)
if 'prev' in content:
content['links'].append({
'rel': 'prev',
'type': FORMAT_TYPES[request.format],
'href': f"{self.get_collections_url()}/{dataset}/items/{content['prev']}?f={request.format}" # noqa
'type': FORMAT_TYPES[link_request_format],
'href': f"{self.get_collections_url()}/{dataset}/items/{content['prev']}?f={link_request_format}" # noqa
})
if 'next' in content:
content['links'].append({
'rel': 'next',
'type': FORMAT_TYPES[request.format],
'href': f"{self.get_collections_url()}/{dataset}/items/{content['next']}?f={request.format}" # noqa
'type': FORMAT_TYPES[link_request_format],
'href': f"{self.get_collections_url()}/{dataset}/items/{content['next']}?f={link_request_format}" # noqa
})
# Set response language to requested provider locale