comparison mercurial/hgweb/request.py @ 36853:ed0456fde625

hgweb: handle CONTENT_LENGTH PEP 3333 says CONTENT_LENGTH may be set. I /think/ WSGI servers are allowed to invent this key even if the client didn't send it. We had code in wireprotoserver looking for this key. So let's just automagically convert this key to an HTTP request header when parsing the request. Differential Revision: https://phab.mercurial-scm.org/D2744
author Gregory Szorc <gregory.szorc@gmail.com>
date Sat, 10 Mar 2018 10:45:12 -0800
parents f9078c6caeb6
children 16292bbda39c
comparison
equal deleted inserted replaced
36852:14f70c44af6c 36853:ed0456fde625
198 if k.startswith('HTTP_'): 198 if k.startswith('HTTP_'):
199 headers.append((k[len('HTTP_'):].replace('_', '-'), v)) 199 headers.append((k[len('HTTP_'):].replace('_', '-'), v))
200 200
201 headers = wsgiheaders.Headers(headers) 201 headers = wsgiheaders.Headers(headers)
202 202
203 # This is kind of a lie because the HTTP header wasn't explicitly
204 # sent. But for all intents and purposes it should be OK to lie about
205 # this, since a consumer will either either value to determine how many
206 # bytes are available to read.
207 if 'CONTENT_LENGTH' in env and 'HTTP_CONTENT_LENGTH' not in env:
208 headers['Content-Length'] = env['CONTENT_LENGTH']
209
203 return parsedrequest(url=fullurl, baseurl=baseurl, 210 return parsedrequest(url=fullurl, baseurl=baseurl,
204 advertisedurl=advertisedfullurl, 211 advertisedurl=advertisedfullurl,
205 advertisedbaseurl=advertisedbaseurl, 212 advertisedbaseurl=advertisedbaseurl,
206 apppath=apppath, 213 apppath=apppath,
207 dispatchparts=dispatchparts, dispatchpath=dispatchpath, 214 dispatchparts=dispatchparts, dispatchpath=dispatchpath,