diff --git a/radicale/__init__.py b/radicale/__init__.py index e4658179..70c88b97 100644 --- a/radicale/__init__.py +++ b/radicale/__init__.py @@ -607,14 +607,12 @@ class Application: if not item: return NOT_FOUND if isinstance(item, storage.BaseCollection): - collection = item - if collection.get_meta("tag") not in ( - "VADDRESSBOOK", "VCALENDAR"): + tag = item.get_meta("tag") + if not tag: return DIRECTORY_LISTING + content_type = xmlutils.MIMETYPES[tag] else: - collection = item.collection - content_type = xmlutils.MIMETYPES.get( - collection.get_meta("tag"), "text/plain") + content_type = xmlutils.OBJECT_MIMETYPES[item.name] headers = { "Content-Type": content_type, "Last-Modified": item.last_modified, diff --git a/radicale/tests/test_base.py b/radicale/tests/test_base.py index 0038a660..122ec5aa 100644 --- a/radicale/tests/test_base.py +++ b/radicale/tests/test_base.py @@ -63,6 +63,7 @@ class BaseRequestsMixIn: status, headers, answer = self.request("GET", path) assert status == 200 assert "ETag" in headers + assert headers["Content-Type"] == "text/calendar; charset=utf-8" assert "VEVENT" in answer assert "Event" in answer assert "UID:event" in answer @@ -102,6 +103,7 @@ class BaseRequestsMixIn: status, headers, answer = self.request("GET", path) assert status == 200 assert "ETag" in headers + assert headers["Content-Type"] == "text/calendar; charset=utf-8" assert "VTODO" in answer assert "Todo" in answer assert "UID:todo" in answer @@ -132,6 +134,7 @@ class BaseRequestsMixIn: status, headers, answer = self.request("GET", path) assert status == 200 assert "ETag" in headers + assert headers["Content-Type"] == "text/vcard; charset=utf-8" assert "VCARD" in answer assert "UID:contact1" in answer status, _, answer = self.request("GET", path) diff --git a/radicale/xmlutils.py b/radicale/xmlutils.py index f0d8665e..adfb363b 100644 --- a/radicale/xmlutils.py +++ b/radicale/xmlutils.py @@ -42,6 +42,11 @@ MIMETYPES = { "VADDRESSBOOK": "text/vcard", "VCALENDAR": "text/calendar"} +OBJECT_MIMETYPES = { + "VCARD": "text/vcard", + "VLIST": "text/x-vlist", + "VCALENDAR": "text/calendar"} + NAMESPACES = { "C": "urn:ietf:params:xml:ns:caldav", "CR": "urn:ietf:params:xml:ns:carddav",