From 5615464923b3ccd627a90d7b79e21c155688781d Mon Sep 17 00:00:00 2001 From: benoitc Date: Wed, 4 Jul 2012 09:34:12 +0200 Subject: [PATCH] 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. --- gunicorn/workers/async.py | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/gunicorn/workers/async.py b/gunicorn/workers/async.py index 2b2619f0..4258d74b 100644 --- a/gunicorn/workers/async.py +++ b/gunicorn/workers/async.py @@ -30,13 +30,18 @@ class AsyncWorker(base.Worker): try: parser = http.RequestParser(self.cfg, client) try: - while True: - req = None - with self.timeout_ctx(): - req = parser.next() - if not req: - break + if not self.cfg.keepalive: + req = parser.next() 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: self.log.debug("Ignored premature client disconnection. %s", e) except StopIteration, e: @@ -66,6 +71,10 @@ class AsyncWorker(base.Worker): self.log.info("Autorestarting worker after current request.") resp.force_close() self.alive = False + + if not self.cfg.keepalive: + resp.force_close() + respiter = self.wsgi(environ, resp.start_response) if respiter == ALREADY_HANDLED: return False