[PATCH] hgweb: log headers only if headers were successfully parsed

David Soria Parra dsp at experimentalworks.net
Wed Oct 2 02:55:42 CDT 2013


# HG changeset patch
# User David Soria Parra <dsp at experimentalworks.net>
# Date 1380614086 -7200
#      Tue Oct 01 09:54:46 2013 +0200
# Node ID 338965ebe8cb9dce835198f7ec685a8c06936563
# Parent  306779c2ef236ec86ab2ddf21195c28ea9a7c4d3
hgweb: log headers only if headers were successfully parsed

The headers attribute is not initialized in certain error situations
(e.g. http 400 bad request). Check for self.headers before we attempt
to access it.

diff --git a/mercurial/hgweb/server.py b/mercurial/hgweb/server.py
--- a/mercurial/hgweb/server.py
+++ b/mercurial/hgweb/server.py
@@ -60,7 +60,9 @@
         self._log_any(self.server.accesslog, format, *args)
 
     def log_request(self, code='-', size='-'):
-        xheaders = [h for h in self.headers.items() if h[0].startswith('x-')]
+        xheaders = []
+        if util.safehasattr(self, 'headers'):
+            xheaders = [h for h in self.headers.items() if h[0].startswith('x-')]
         self.log_message('"%s" %s %s%s',
                          self.requestline, str(code), str(size),
                          ''.join([' %s:%s' % h for h in sorted(xheaders)]))


More information about the Mercurial-devel mailing list