From 5121e9aba61050d781b8898bb66e6cd18c5d8f4d Mon Sep 17 00:00:00 2001
From: Markus Scheidgen <markus.scheidgen@gmail.com>
Date: Tue, 5 Jan 2021 17:13:42 +0100
Subject: [PATCH] Change the content type based on the given format parameter.

---
 nomad/app/dcat/catalog.py  | 3 ++-
 nomad/app/dcat/datasets.py | 3 ++-
 2 files changed, 4 insertions(+), 2 deletions(-)

diff --git a/nomad/app/dcat/catalog.py b/nomad/app/dcat/catalog.py
index 54c7d7ceb1..e402579cb1 100644
--- a/nomad/app/dcat/catalog.py
+++ b/nomad/app/dcat/catalog.py
@@ -73,7 +73,8 @@ class Catalog(Resource):
 
         mapping = Mapping()
         mapping.map_catalog(es_response.hits)
+        content_type = 'application/xml' if format_ == 'xml' else 'text/%s' % format_
 
         return Response(
             mapping.g.serialize(format=format_).decode('utf-8'), 200,
-            {'Content-Type': 'application/xml'})
+            {'Content-Type': content_type})
diff --git a/nomad/app/dcat/datasets.py b/nomad/app/dcat/datasets.py
index 176ec90c92..aee3aff045 100644
--- a/nomad/app/dcat/datasets.py
+++ b/nomad/app/dcat/datasets.py
@@ -59,6 +59,7 @@ class Dataset(Resource):
 
         mapping = Mapping()
         mapping.map_entry(entry)
+        content_type = 'application/xml' if format_ == 'xml' else 'text/%s' % format_
         return Response(
             mapping.g.serialize(format=format_).decode('utf-8'), 200,
-            {'Content-Type': 'application/xml'})
+            {'Content-Type': content_type})
-- 
GitLab