From fab7796ca0b0145adb1ac8e543d52044dde2b8c5 Mon Sep 17 00:00:00 2001 From: Guillaume Ayoub Date: Mon, 13 May 2013 18:15:08 +0200 Subject: [PATCH] Allow additional HTTP headers in configuration file Best ratio coolness/sloc ever! --- config | 5 +++++ radicale/__init__.py | 4 ++++ 2 files changed, 9 insertions(+) diff --git a/config b/config index 4f8a458..bf0c85d 100644 --- a/config +++ b/config @@ -126,3 +126,8 @@ config = /etc/radicale/logging debug = False # Store all environment variables (including those set in the shell) full_environment = False + + +# Additional HTTP headers +#[headers] +#Access-Control-Allow-Origin = * diff --git a/radicale/__init__.py b/radicale/__init__.py index 6d6b7c0..f022f95 100644 --- a/radicale/__init__.py +++ b/radicale/__init__.py @@ -313,6 +313,10 @@ class Application(object): "Response content:\n%s" % self.decode(answer, environ)) headers["Content-Length"] = str(len(answer)) + if config.has_section("headers"): + for key in config.options("headers"): + headers[key] = config.get("headers", key) + # Start response status = "%i %s" % (status, client.responses.get(status, "Unknown")) log.LOGGER.debug("Answer status: %s" % status)