Add server/base_prefix setting.
authorJelmer Vernooij <jelmer@debian.org>
Sat, 8 Mar 2014 23:39:54 +0000 (23:39 +0000)
committerJelmer Vernooij <jelmer@jelmer.uk>
Wed, 13 Jan 2016 02:15:16 +0000 (02:15 +0000)
calypso/config.py
calypso/paths.py
config

index 598d1e2994f691e6040427c3a5959a75dc268d6b..dc17eec8adc640a9d4dfbb4b6cdf44370af7fda2 100644 (file)
@@ -47,6 +47,7 @@ INITIAL_CONFIG = {
         "key": "/etc/apache2/ssl/server.key",
         "pidfile": "/var/run/calypso.pid",
         "user_principal": "/+%(user)s",
+        "base_prefix": "/",
     },
     "encoding": {
         "request": "utf-8",
index 11640aa4575510cc2efb89130aad813ab8592cea..d69b6673489aa192ace6e836ac99c67f5a5f5ccb 100644 (file)
@@ -45,6 +45,14 @@ def url_to_owner(path):
 def data_root():
     return os.path.expanduser(config.get("storage", "folder"))
 
+
+#
+# Return the base path for the web server.
+#
+
+def base_prefix():
+    return config.get("server", "base_prefix").rstrip("/")
+
 #
 # Given a URL, convert it to an absolute path name by
 # prepending the storage folder name
@@ -53,12 +61,15 @@ def data_root():
 #
 
 def url_to_file(url):
+    if url.startswith(base_prefix()):
+        url = "/" + url[len(base_prefix()):].lstrip("/")
     tail = urllib.url2pathname(url.strip("/"))
     # eliminate .. components, and potential double leading slashes
     tail = posixpath.normpath('/' + tail).lstrip('/')
     file = os.path.join(data_root(), tail)
     return file
 
+
 #
 # Does the provided URL reference a collection? This
 # is done by seeing if the resulting path is a directory
diff --git a/config b/config
index 90c739f2db737411754b9112708a4fe196f19797..1ef574c0ef08fa015e1e10e01dd3f97aae81e80e 100644 (file)
--- a/config
+++ b/config
@@ -23,6 +23,8 @@ key = /etc/apache2/ssl/server.key
 # current user principal; path to the default collection for a user
 # for clients that use it (RFC5397)
 user_principal = /+%(user)s
+# base URL if / is not the CalDAV root
+base_prefix = /
 
 [encoding]
 # Encoding for responding requests