mirror of
https://github.com/django/django.git
synced 2024-12-25 02:26:12 +00:00
Cleaned up WSGIRequestHandler get_environ to be Python 3 compatible
headers.type/typeheader attributes are gone in Python 3. Thanks Vinay Sajip for the inspiration of his Python 3 branch.
This commit is contained in:
parent
02eca6c0e2
commit
91727c76cd
@ -146,25 +146,23 @@ class WSGIRequestHandler(simple_server.WSGIRequestHandler, object):
|
|||||||
env['PATH_INFO'] = urllib.unquote(path)
|
env['PATH_INFO'] = urllib.unquote(path)
|
||||||
env['QUERY_STRING'] = query
|
env['QUERY_STRING'] = query
|
||||||
env['REMOTE_ADDR'] = self.client_address[0]
|
env['REMOTE_ADDR'] = self.client_address[0]
|
||||||
|
env['CONTENT_TYPE'] = self.headers.get('content-type', 'text/plain')
|
||||||
|
|
||||||
if self.headers.typeheader is None:
|
length = self.headers.get('content-length')
|
||||||
env['CONTENT_TYPE'] = self.headers.type
|
|
||||||
else:
|
|
||||||
env['CONTENT_TYPE'] = self.headers.typeheader
|
|
||||||
|
|
||||||
length = self.headers.getheader('content-length')
|
|
||||||
if length:
|
if length:
|
||||||
env['CONTENT_LENGTH'] = length
|
env['CONTENT_LENGTH'] = length
|
||||||
|
|
||||||
for h in self.headers.headers:
|
for key, value in self.headers.items():
|
||||||
k,v = h.split(':',1)
|
key = key.replace('-','_').upper()
|
||||||
k=k.replace('-','_').upper(); v=v.strip()
|
value = value.strip()
|
||||||
if k in env:
|
if key in env:
|
||||||
continue # skip content length, type,etc.
|
# Skip content length, type, etc.
|
||||||
if 'HTTP_'+k in env:
|
continue
|
||||||
env['HTTP_'+k] += ','+v # comma-separate multiple headers
|
if 'HTTP_' + key in env:
|
||||||
|
# Comma-separate multiple headers
|
||||||
|
env['HTTP_' + key] += ',' + value
|
||||||
else:
|
else:
|
||||||
env['HTTP_'+k] = v
|
env['HTTP_' + key] = value
|
||||||
return env
|
return env
|
||||||
|
|
||||||
def log_message(self, format, *args):
|
def log_message(self, format, *args):
|
||||||
|
Loading…
Reference in New Issue
Block a user