diff mercurial/hgweb/protocol.py @ 30759:3f5f0c98cd18

httppeer: extract code for HTTP header spanning A second consumer of HTTP header spanning will soon be introduced. Factor out the code to do this so it can be reused.
author Gregory Szorc <gregory.szorc@gmail.com>
date Sat, 24 Dec 2016 14:46:02 -0700
parents b3a9ef3d30e8
children e75463e3179f
line wrap: on
line diff
--- a/mercurial/hgweb/protocol.py	Tue Jan 10 11:20:32 2017 -0800
+++ b/mercurial/hgweb/protocol.py	Sat Dec 24 14:46:02 2016 -0700
@@ -25,6 +25,20 @@
 HGTYPE = 'application/mercurial-0.1'
 HGERRTYPE = 'application/hg-error'
 
+def decodevaluefromheaders(req, headerprefix):
+    """Decode a long value from multiple HTTP request headers."""
+    chunks = []
+    i = 1
+    while True:
+        v = req.env.get('HTTP_%s_%d' % (
+            headerprefix.upper().replace('-', '_'), i))
+        if v is None:
+            break
+        chunks.append(v)
+        i += 1
+
+    return ''.join(chunks)
+
 class webproto(wireproto.abstractserverproto):
     def __init__(self, req, ui):
         self.req = req
@@ -53,15 +67,9 @@
             args.update(cgi.parse_qs(
                 self.req.read(postlen), keep_blank_values=True))
             return args
-        chunks = []
-        i = 1
-        while True:
-            h = self.req.env.get('HTTP_X_HGARG_' + str(i))
-            if h is None:
-                break
-            chunks += [h]
-            i += 1
-        args.update(cgi.parse_qs(''.join(chunks), keep_blank_values=True))
+
+        argvalue = decodevaluefromheaders(self.req, 'X-HgArg')
+        args.update(cgi.parse_qs(argvalue, keep_blank_values=True))
         return args
     def getfile(self, fp):
         length = int(self.req.env['CONTENT_LENGTH'])