hgweb: fix decodevaluefromheaders to always return a bytes value
authorAugie Fackler <augie@google.com>
Sun, 15 Oct 2017 00:43:01 -0400
changeset 34744 0a2ef612ad50
parent 34743 dc2bf7074147
child 34745 0b46440b1b45
hgweb: fix decodevaluefromheaders to always return a bytes value That's more in line with what we want, and we know it's ASCII data since that's all HTTP technically allows in headers anyway. Differential Revision: https://phab.mercurial-scm.org/D1112
mercurial/hgweb/protocol.py
--- a/mercurial/hgweb/protocol.py	Sun Oct 15 00:42:25 2017 -0400
+++ b/mercurial/hgweb/protocol.py	Sun Oct 15 00:43:01 2017 -0400
@@ -30,15 +30,18 @@
 HGERRTYPE = 'application/hg-error'
 
 def decodevaluefromheaders(req, headerprefix):
-    """Decode a long value from multiple HTTP request headers."""
+    """Decode a long value from multiple HTTP request headers.
+
+    Returns the value as a bytes, not a str.
+    """
     chunks = []
     i = 1
+    prefix = headerprefix.upper().replace(r'-', r'_')
     while True:
-        v = req.env.get('HTTP_%s_%d' % (
-            headerprefix.upper().replace('-', '_'), i))
+        v = req.env.get(r'HTTP_%s_%d' % (prefix, i))
         if v is None:
             break
-        chunks.append(v)
+        chunks.append(pycompat.bytesurl(v))
         i += 1
 
     return ''.join(chunks)