add custom headers via config file
authorchrysn <chrysn@fsfe.org>
Tue, 15 Apr 2014 17:57:38 +0000 (19:57 +0200)
committerJelmer Vernooń≥ <jelmer@jelmer.uk>
Sat, 9 Apr 2016 22:48:40 +0000 (22:48 +0000)
this is required when using calypso with a web application on a
different server

calypso/__init__.py
calypso/config.py
config

index 40987dd..da02962 100644 (file)
@@ -172,6 +172,9 @@ class CollectionHTTPHandler(server.BaseHTTPRequestHandler):
         self.send_response(response)
         self.send_connection_header()
         self.send_header("Content-Length", length)
+        for header, value in config.items('headers'):
+            self.send_header(header, value)
+
 
     def handle_one_request(self):
         """Handle a single HTTP request.
index 59cbd85..0c3fee9 100644 (file)
@@ -60,7 +60,11 @@ INITIAL_CONFIG = {
         "pam_service": "passwd",
     },
     "storage": {
-        "folder": os.path.expanduser("~/.config/calypso/calendars")}}
+        "folder": os.path.expanduser("~/.config/calypso/calendars")
+    },
+    "headers": {
+    },
+}
 
 # Create a ConfigParser and configure it
 _CONFIG_PARSER = ConfigParser()
diff --git a/config b/config
index 1ef574c..7093716 100644 (file)
--- a/config
+++ b/config
@@ -51,4 +51,15 @@ encryption = crypt
 # created if not present
 folder = ~/.config/calypso/calendars
 
+# The headers section allows verbatim addition of static headers to
+# responses. The following exemplary headers are useful when the calendar
+# should be accessed from users' web browsers using a web application hosted on
+# a different server.
+#
+#[headers]
+#Access-Control-Allow-Origin = *
+#Access-Control-Allow-Credentials = *
+#Access-Control-Allow-Methods = GET, POST, PUT, DELETE, PROPFIND, REPORT
+#Access-Control-Allow-Headers = accept, authorization, content-type, depth, x-client, if-match
+
 # vim:ft=cfg