implement rfc6764 /.well-known/{card,cal}dav addresses
authorchrysn <chrysn@fsfe.org>
Thu, 14 Aug 2014 07:49:59 +0000 (09:49 +0200)
committerJelmer Vernooń≥ <jelmer@jelmer.uk>
Sun, 10 Apr 2016 11:43:29 +0000 (11:43 +0000)
those are required vor DAVDroid around 0.6.2.

the patch requires a do_get_head mechanism in the Resource class, which
can be used in general for non-collection resources to implement their
own responses.

calypso/__init__.py
calypso/principal.py

index c8c5260..960ad82 100644 (file)
@@ -150,6 +150,9 @@ def identify_resource(path):
     """Return a Resource object corresponding to the path (this is used for
     everything that is not a collection, like Principal and HomeSet objects)"""
 
+    if path in ("/.well-known/carddav", "/.well-known/caldav"):
+        return principal.WellKnownDav()
+
     try:
         left, right = config.get('server', 'user_principal').split('%(user)s')
     except ValueError:
@@ -357,6 +360,9 @@ class CollectionHTTPHandler(server.BaseHTTPRequestHandler):
                 if is_get:
                     answer_text = self._collection.text
                 etag = self._collection.etag
+            elif self._resource:
+                self._resource.do_get_head(self, context, is_get)
+                return
             else:
                 self.send_calypso_response(client.NOT_FOUND, 0)
                 self.end_headers()
index 65e8d4f..f6880c4 100644 (file)
@@ -19,8 +19,25 @@ class Resource(acl.Entity):
         responded with to a propfind of a given depth"""
         return [self]
 
+    def do_get_head(self, request, context, is_get):
+        """Handle an incoming GET or HEAD request. See
+        CollectionHTTPHandler.do_get_head for what this usually should do."""
+        request.send_calypso_response(404, 0)
+        request.end_headers()
+
     urlpath = None # this should be present ... implement as abstract property?
 
+class WellKnownDav(Resource):
+    def has_right(self, user):
+        return True
+
+    def do_get_head(self, request, context, is_get):
+        """According to RFC6764, redirect to a context path (from where
+        current-user-principal can be discovered)"""
+        request.send_calypso_response(303, 0)
+        request.send_header("Location", config.get("server", "base_prefix"))
+        request.end_headers()
+
 class Principal(Resource):
     def __init__(self, username):
         self.username = username