diff --git a/NEWS b/NEWS index 4d49c5c..cf2cce4 100644 --- a/NEWS +++ b/NEWS @@ -9,6 +9,8 @@ 0.5 - **Not released yet** ========================== +* Last-Modified HTTP header + 0.3 - Dancing Flowers ===================== diff --git a/radicale/__init__.py b/radicale/__init__.py index 33423d4..ab20a82 100644 --- a/radicale/__init__.py +++ b/radicale/__init__.py @@ -169,6 +169,7 @@ class CalendarHTTPHandler(server.BaseHTTPRequestHandler): self.send_response(client.OK) self.send_header("Content-Length", len(answer)) self.send_header("Content-Type", "text/calendar") + self.send_header("Last-Modified", self._calendar.last_modified) self.send_header("ETag", etag) self.end_headers() self.wfile.write(answer) diff --git a/radicale/ical.py b/radicale/ical.py index 7f88fa6..d265f49 100644 --- a/radicale/ical.py +++ b/radicale/ical.py @@ -27,6 +27,7 @@ Define the main classes of a calendar as seen from the server. import os import codecs +import time from radicale import config @@ -136,6 +137,9 @@ class Calendar(object): self.encoding = "utf-8" self.owner = path.split("/")[0] self.path = os.path.join(FOLDER, path.replace("/", os.path.sep)) + # Create calendar if needed, useful for ``self.last_modified`` + if not os.path.exists(self.path): + self.write() @staticmethod def _parse(text, item_types, name=None): @@ -267,3 +271,13 @@ class Calendar(object): def timezones(self): """Get list of ``Timezome`` items in calendar.""" return self._parse(self.text, (Timezone,)) + + @property + def last_modified(self): + """Get the last time the calendar has been modified. + + The date is formatted according to rfc1123-5.2.14. + + """ + modification_time = time.localtime(os.path.getmtime(self.path)) + return time.strftime("%a, %d %b %Y %H:%M:%S %Z", modification_time)