[Calypso] [PATCH] Add 'base_prefix' setting to support serving at non-root path.
Jelmer Vernooij
jelmer at jelmer.uk
Mon Nov 30 16:21:34 PST 2015
---
calypso/config.py | 1 +
calypso/paths.py | 11 +++++++++++
calypso/xmlutils.py | 2 +-
config | 2 ++
4 files changed, 15 insertions(+), 1 deletion(-)
diff --git a/calypso/config.py b/calypso/config.py
index 598d1e2..dc17eec 100644
--- a/calypso/config.py
+++ b/calypso/config.py
@@ -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",
diff --git a/calypso/paths.py b/calypso/paths.py
index 11640aa..d69b667 100644
--- a/calypso/paths.py
+++ b/calypso/paths.py
@@ -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/calypso/xmlutils.py b/calypso/xmlutils.py
index 47c9846..3a04bc9 100644
--- a/calypso/xmlutils.py
+++ b/calypso/xmlutils.py
@@ -212,7 +212,7 @@ def propfind(path, xml_request, collection, depth, context):
element.text = email.utils.formatdate(time.mktime(item.last_modified))
elif tag == _tag("D", "current-user-principal"):
tag = ET.Element(_tag("D", "href"))
- tag.text = config.get("server", "user_principal") % context
+ tag.text = paths.base_prefix() + config.get("server", "user_principal") % context
element.append(tag)
elif tag == _tag("A", "addressbook-description") and is_collection:
element.text = collection.read_file(".git/description")
diff --git a/config b/config
index 90c739f..1ef574c 100644
--- 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
--
2.6.2
More information about the Calypso
mailing list