Patchwork hgweb: log headers only if headers were successfully parsed

login
register
mail settings
Submitter David Soria Parra
Date Oct. 2, 2013, 7:55 a.m.
Message ID <338965ebe8cb9dce8351.1380700542@achird.localdomain>
Download mbox | patch
Permalink /patch/2690/
State Accepted
Commit 52ed85d9ac265e27ef363fd7e03042194e2f9841
Headers show

Comments

David Soria Parra - Oct. 2, 2013, 7:55 a.m.
# HG changeset patch
# User David Soria Parra <dsp@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.
Matt Mackall - Oct. 2, 2013, 9 p.m.
On Wed, 2013-10-02 at 09:55 +0200, David Soria Parra wrote:
> # HG changeset patch
> # User David Soria Parra <dsp@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.

This looks like it belongs on stable, no? Queued for stable. Check-code
sends its regards.

Patch

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)]))