changeset 678:48787c662e1a

add 404 handling and cache headers for action=raw
author Thomas Waldmann <tw AT waldmann-edv DOT de>
date Sun, 21 May 2006 13:33:18 +0200
parents eb26ef73b4ca
children 421b68c6533b
files MoinMoin/Page.py
diffstat 1 files changed, 18 insertions(+), 4 deletions(-) [+]
line wrap: on
line diff
--- a/MoinMoin/Page.py	Sun May 21 00:39:21 2006 +0200
+++ b/MoinMoin/Page.py	Sun May 21 13:33:18 2006 +0200
@@ -955,10 +955,24 @@
 
     def send_raw(self):
         """ Output the raw page data (action=raw) """
-        self.request.http_headers(["Content-type: text/plain;charset=%s" % config.charset])
-        text = self.get_raw_body()
-        text = self.encodeTextMimeType(text)
-        self.request.write(text)
+        request = self.request
+        request.http_headers(["Content-type: text/plain;charset=%s" % config.charset])
+        if self.exists():
+            if not request.cacheable:
+                request.http_headers(request.nocache)
+            else:
+                # use the correct last-modified value from the on-disk file
+                # to ensure cacheability where supported
+                request.http_headers(["Last-Modified: " +
+                     timefuncs.formathttpdate(os.path.getmtime(self._text_filename()))])
+
+            text = self.get_raw_body()
+            text = self.encodeTextMimeType(text)
+            request.write(text)
+        else:
+            request.http_headers(['Status: 404 NOTFOUND'])
+            request.setResponseCode(404)
+            request.write(u"Page %s not found." % self.page_name)
 
 
     def send_page(self, request, msg=None, **keywords):