From dc8d6541d95d6319ecfe362075f454142d261763 Mon Sep 17 00:00:00 2001 From: Edmond Chuc Date: Tue, 5 Jul 2022 04:57:34 +0000 Subject: [PATCH] Set default format when accept header includes multiple formats --- src/linkeddata_api/views/api_v1/resource/__init__.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/linkeddata_api/views/api_v1/resource/__init__.py b/src/linkeddata_api/views/api_v1/resource/__init__.py index 74c5a1b..1005f85 100644 --- a/src/linkeddata_api/views/api_v1/resource/__init__.py +++ b/src/linkeddata_api/views/api_v1/resource/__init__.py @@ -17,7 +17,9 @@ def get_resource(): repository_id = request.args.get("repository_id") uri = request.args.get("uri") format_ = request.headers.get("accept") - if not format_: + # TODO: Support 'format' query arg? It would make it easier to configure persistent redirect services. + # TODO: Curently we don't support multiple format types. + if not format_ or "," in format_: format_ = "text/turtle" include_incoming_relationships = request.args.get("include_incoming_relationships") include_incoming_relationships = ( @@ -39,7 +41,8 @@ def get_resource(): ) from err graph = rdf.create_graph() - graph.parse(data=response.text) + + graph.parse(data=response.text, format=format_) if len(graph) == 0: return "Resource not found", 404