changeset 1070:054a3d3d8dfe

fix http headers for edit, RenamePage, DeletePage action, raise exception when http_headers is called multiple times
author Thomas Waldmann <tw AT waldmann-edv DOT de>
date Thu, 27 Jul 2006 11:28:35 +0200
parents d7227430c305
children 64e513264aed
files MoinMoin/Page.py MoinMoin/action/edit.py MoinMoin/request/__init__.py
diffstat 3 files changed, 27 insertions(+), 25 deletions(-) [+]
line wrap: on
line diff
--- a/MoinMoin/Page.py	Thu Jul 27 10:10:32 2006 +0200
+++ b/MoinMoin/Page.py	Thu Jul 27 11:28:35 2006 +0200
@@ -989,7 +989,7 @@
 
         @param request: the request object
         @param msg: if given, display message in header area
-        @keyword content_only: if 1, omit page header and footer
+        @keyword content_only: if 1, omit http headers, page header and footer
         @keyword content_id: set the id of the enclosing div
         @keyword count_hit: if 1, add an event to the log
         @keyword send_missing_page: if 1, assume that page to be sent is MissingPage
@@ -1157,30 +1157,28 @@
 
         # start document output
         doc_leader = self.formatter.startDocument(self.page_name)
-
-        request.setHttpHeader("Content-Type: %s; charset=%s" % (self.output_mimetype, self.output_charset))
-
         page_exists = self.exists()
-        if page_exists:
-            request.setHttpHeader('Status: 200 OK')
-            if not request.cacheable or request.user.valid:
-                # use "nocache" headers if we're using a method that
-                # is not simply "display", or if a user is logged in
-                # (which triggers personalisation features)
-                for header in request.nocache:
-                    request.setHttpHeader(header)
+        if not content_only:
+            request.setHttpHeader("Content-Type: %s; charset=%s" % (self.output_mimetype, self.output_charset))
+            if page_exists:
+                request.setHttpHeader('Status: 200 OK')
+                if not request.cacheable or request.user.valid:
+                    # use "nocache" headers if we're using a method that
+                    # is not simply "display", or if a user is logged in
+                    # (which triggers personalisation features)
+                    for header in request.nocache:
+                        request.setHttpHeader(header)
+                else:
+                    # TODO: we need to know if a page generates dynamic content
+                    # if it does, we must not use the page file mtime as last modified value
+                    # XXX The following code is commented because it is incorrect for dynamic pages:
+                    #lastmod = os.path.getmtime(self._text_filename())
+                    #request.setHttpHeader("Last-Modified: %s" % timefuncs.formathttpdate(lastmod))
+                    pass
             else:
-                # TODO: we need to know if a page generates dynamic content
-                # if it does, we must not use the page file mtime as last modified value
-                # XXX The following code is commented because it is incorrect for dynamic pages:
-                #lastmod = os.path.getmtime(self._text_filename())
-                #request.setHttpHeader("Last-Modified: %s" % timefuncs.formathttpdate(lastmod))
-                pass
-        else:
-            request.setHttpHeader('Status: 404 NOTFOUND')
+                request.setHttpHeader('Status: 404 NOTFOUND')
+            request.emit_http_headers()
 
-        request.emit_http_headers()
-        if not content_only:
             request.write(doc_leader)
 
             # send the page header
--- a/MoinMoin/action/edit.py	Thu Jul 27 10:10:32 2006 +0200
+++ b/MoinMoin/action/edit.py	Thu Jul 27 11:28:35 2006 +0200
@@ -137,7 +137,6 @@
         try:
             still_conflict = wikiutil.containsConflictMarker(savetext)
             pg.setConflict(still_conflict)
-            request.emit_http_headers() # XXX WHY? XXX
             savemsg = pg.saveText(savetext, rev, trivial=trivial, comment=comment)
         except pg.EditConflict, e:
             msg = e.message
--- a/MoinMoin/request/__init__.py	Thu Jul 27 10:10:32 2006 +0200
+++ b/MoinMoin/request/__init__.py	Thu Jul 27 11:28:35 2006 +0200
@@ -1137,9 +1137,14 @@
             @param more_headers: list of additional header strings
         """
         # Send headers only once
-        if getattr(self, 'sent_headers', False):
+        sent_headers = getattr(self, 'sent_headers', 0)
+        self.sent_headers = sent_headers + 1
+        if sent_headers:
+            raise("emit_http_headers called multiple times(%d)! Headers: %r" % (sent_headers, more_headers))
+            self.log("emit_http_headers called multiple times(%d)! Headers: %r" % (sent_headers, more_headers))
             return
-        self.sent_headers = True
+        else:
+            self.log("Notice: emit_http_headers called first time. Headers: %r" % more_headers)
 
         content_type = None
         status = None