don't reread headers' list to add them to the environ. Instead read them

once time.
This commit is contained in:
benoitc 2010-08-11 12:02:49 +02:00
parent 7873ba7398
commit 4e3d09c64d

View File

@ -31,6 +31,7 @@ def create(req, sock, client, server, cfg):
script_name = os.environ.get("SCRIPT_NAME", "") script_name = os.environ.get("SCRIPT_NAME", "")
content_type = "" content_type = ""
content_length = "" content_length = ""
for hdr_name, hdr_value in req.headers: for hdr_name, hdr_value in req.headers:
if hdr_name == "EXPECT": if hdr_name == "EXPECT":
# handle expect # handle expect
@ -50,8 +51,10 @@ def create(req, sock, client, server, cfg):
content_type = hdr_value content_type = hdr_value
elif hdr_name == "CONTENT-LENGTH": elif hdr_name == "CONTENT-LENGTH":
content_length = hdr_value content_length = hdr_value
else:
continue key = 'HTTP_' + hdr_name.replace('-', '_')
if key not in ('HTTP_CONTENT_TYPE', 'HTTP_CONTENT_LENGTH'):
environ[key] = hdr_value
wsgi_multiprocess = (cfg.workers > 1) wsgi_multiprocess = (cfg.workers > 1)
@ -81,7 +84,7 @@ def create(req, sock, client, server, cfg):
if script_name: if script_name:
path_info = path_info.split(script_name, 1)[1] path_info = path_info.split(script_name, 1)[1]
environ = { environ.update({
"wsgi.url_scheme": url_scheme, "wsgi.url_scheme": url_scheme,
"wsgi.input": req.body, "wsgi.input": req.body,
"wsgi.errors": sys.stderr, "wsgi.errors": sys.stderr,
@ -103,12 +106,7 @@ def create(req, sock, client, server, cfg):
"SERVER_NAME": server[0], "SERVER_NAME": server[0],
"SERVER_PORT": str(server[1]), "SERVER_PORT": str(server[1]),
"SERVER_PROTOCOL": "HTTP/%s" % ".".join(map(str, req.version)) "SERVER_PROTOCOL": "HTTP/%s" % ".".join(map(str, req.version))
} })
for key, value in req.headers:
key = 'HTTP_' + key.replace('-', '_')
if key not in ('HTTP_CONTENT_TYPE', 'HTTP_CONTENT_LENGTH'):
environ[key] = value
return resp, environ return resp, environ