changeset 2934:2521eb511f77

log duplicate header emissions with tracebacks
author Johannes Berg <johannes AT sipsolutions DOT net>
date Tue, 30 Oct 2007 14:41:54 +0100
parents 5ad34b3541e6
children 3670e156ec1a
files MoinMoin/request/__init__.py MoinMoin/request/_tests/test_request.py
diffstat 2 files changed, 8 insertions(+), 5 deletions(-) [+]
line wrap: on
line diff
--- a/MoinMoin/request/__init__.py	Tue Oct 30 14:34:57 2007 +0100
+++ b/MoinMoin/request/__init__.py	Tue Oct 30 14:41:54 2007 +0100
@@ -150,7 +150,7 @@
         # Pages meta data that we collect in one request
         self.pages = {}
 
-        self.sent_headers = False
+        self.sent_headers_trace = None
         self.user_headers = []
         self.cacheable = 0 # may this output get cached by http proxies/caches?
         self.http_caching_disabled = 0 # see disableHttpCaching()
@@ -1314,11 +1314,14 @@
         tracehere = ''.join(traceback.format_stack()[:-1])
         all_headers = [(hdr, tracehere) for hdr in more_headers] + user_headers
 
-        if self.sent_headers:
+        if self.sent_headers_trace:
             # Send headers only once
-            raise HeadersAlreadySentException("emit_http_headers has already been called before! Headers: %r" % all_headers)
+            self.log("Attempt to send headers twice!\n")
+            self.log("First attempt:\n%s" % self.sent_headers_trace)
+            self.log("Second attempt:\n%s" % tracehere)
+            raise HeadersAlreadySentException("emit_http_headers has already been called before!")
         else:
-            self.sent_headers = True
+            self.sent_headers_trace = tracehere
 
         # assemble dict of http headers
         headers = {}
--- a/MoinMoin/request/_tests/test_request.py	Tue Oct 30 14:34:57 2007 +0100
+++ b/MoinMoin/request/_tests/test_request.py	Tue Oct 30 14:41:54 2007 +0100
@@ -113,7 +113,7 @@
     std_headers = ['Status: 200 OK', 'Content-type: text/html; charset=%s' % config.charset]
 
     def setup_method(self, method):
-        self.request.sent_headers = False
+        self.request.sent_headers_trace = None
 
     def testAutoAddStdHeaders(self):
         """ test if the usual headers get auto-added if not specified """