handle keepalive = 0

Keepalive=0 means that we aren't waiting for the next connection. So
make sure to send appropriate "close" header and that we handle the first
connection.
This commit is contained in:
benoitc 2012-07-04 09:34:12 +02:00
parent cdd3e1dc2b
commit 5615464923

View File

@ -30,13 +30,18 @@ class AsyncWorker(base.Worker):
try: try:
parser = http.RequestParser(self.cfg, client) parser = http.RequestParser(self.cfg, client)
try: try:
while True: if not self.cfg.keepalive:
req = None req = parser.next()
with self.timeout_ctx():
req = parser.next()
if not req:
break
self.handle_request(req, client, addr) self.handle_request(req, client, addr)
else:
# keepalive loop
while True:
req = None
with self.timeout_ctx():
req = parser.next()
if not req:
break
self.handle_request(req, client, addr)
except http.errors.NoMoreData, e: except http.errors.NoMoreData, e:
self.log.debug("Ignored premature client disconnection. %s", e) self.log.debug("Ignored premature client disconnection. %s", e)
except StopIteration, e: except StopIteration, e:
@ -66,6 +71,10 @@ class AsyncWorker(base.Worker):
self.log.info("Autorestarting worker after current request.") self.log.info("Autorestarting worker after current request.")
resp.force_close() resp.force_close()
self.alive = False self.alive = False
if not self.cfg.keepalive:
resp.force_close()
respiter = self.wsgi(environ, resp.start_response) respiter = self.wsgi(environ, resp.start_response)
if respiter == ALREADY_HANDLED: if respiter == ALREADY_HANDLED:
return False return False