Mercurial > public > mercurial-scm > hg-stable
comparison 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 |
comparison
equal
deleted
inserted
replaced
30758:76104a4899ad | 30759:3f5f0c98cd18 |
---|---|
22 urlerr = util.urlerr | 22 urlerr = util.urlerr |
23 urlreq = util.urlreq | 23 urlreq = util.urlreq |
24 | 24 |
25 HGTYPE = 'application/mercurial-0.1' | 25 HGTYPE = 'application/mercurial-0.1' |
26 HGERRTYPE = 'application/hg-error' | 26 HGERRTYPE = 'application/hg-error' |
27 | |
28 def decodevaluefromheaders(req, headerprefix): | |
29 """Decode a long value from multiple HTTP request headers.""" | |
30 chunks = [] | |
31 i = 1 | |
32 while True: | |
33 v = req.env.get('HTTP_%s_%d' % ( | |
34 headerprefix.upper().replace('-', '_'), i)) | |
35 if v is None: | |
36 break | |
37 chunks.append(v) | |
38 i += 1 | |
39 | |
40 return ''.join(chunks) | |
27 | 41 |
28 class webproto(wireproto.abstractserverproto): | 42 class webproto(wireproto.abstractserverproto): |
29 def __init__(self, req, ui): | 43 def __init__(self, req, ui): |
30 self.req = req | 44 self.req = req |
31 self.response = '' | 45 self.response = '' |
51 postlen = int(self.req.env.get('HTTP_X_HGARGS_POST', 0)) | 65 postlen = int(self.req.env.get('HTTP_X_HGARGS_POST', 0)) |
52 if postlen: | 66 if postlen: |
53 args.update(cgi.parse_qs( | 67 args.update(cgi.parse_qs( |
54 self.req.read(postlen), keep_blank_values=True)) | 68 self.req.read(postlen), keep_blank_values=True)) |
55 return args | 69 return args |
56 chunks = [] | 70 |
57 i = 1 | 71 argvalue = decodevaluefromheaders(self.req, 'X-HgArg') |
58 while True: | 72 args.update(cgi.parse_qs(argvalue, keep_blank_values=True)) |
59 h = self.req.env.get('HTTP_X_HGARG_' + str(i)) | |
60 if h is None: | |
61 break | |
62 chunks += [h] | |
63 i += 1 | |
64 args.update(cgi.parse_qs(''.join(chunks), keep_blank_values=True)) | |
65 return args | 73 return args |
66 def getfile(self, fp): | 74 def getfile(self, fp): |
67 length = int(self.req.env['CONTENT_LENGTH']) | 75 length = int(self.req.env['CONTENT_LENGTH']) |
68 for s in util.filechunkiter(self.req, limit=length): | 76 for s in util.filechunkiter(self.req, limit=length): |
69 fp.write(s) | 77 fp.write(s) |