add custom headers via config file
authorchrysn <chrysn@fsfe.org>
Tue, 15 Apr 2014 17:57:38 +0000 (19:57 +0200)
committerJelmer Vernooij <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 40987dd0b135acf829bc4cacd02bd10caa7fb0a6..da0296258d4074e63512cc85d733ed21f426495c 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 59cbd857a406bdb1e8f80f296e1521f0a5a89931..0c3fee9562f3cdd31d74247c7969966aa12fb34c 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 1ef574c0ef08fa015e1e10e01dd3f97aae81e80e..7093716162bc3f8e36ce9588489c972427911fb4 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