diff --git a/gunicorn/http/__init__.py b/gunicorn/http/__init__.py index 14e2939a..29a553f4 100644 --- a/gunicorn/http/__init__.py +++ b/gunicorn/http/__init__.py @@ -1,3 +1,3 @@ -from message import Message, Request, Response -from parser import Parser, RequestParser, ResponseParser \ No newline at end of file +from message import Message, Request +from parser import RequestParser diff --git a/gunicorn/http/parser.py b/gunicorn/http/parser.py index a5e31bc3..9eb93480 100644 --- a/gunicorn/http/parser.py +++ b/gunicorn/http/parser.py @@ -17,21 +17,22 @@ class Parser(object): return self def next(self): - if self.mesg.should_close(): + # Stop if HTTP dictates a stop. + if self.mesg and self.mesg.should_close(): raise StopIteration() - self.discard() + + # Discard any unread body of the previous message + if self.mesg: + data = self.mesg.body.read(8192) + while data: + data = mesg.body.read(8192) + + # Parse the next request self.mesg = self.mesg_class(self.unreader) if not self.mesg: raise StopIteration() return self.mesg - def discard(self): - if self.mesg is not None: - data = self.mesg.read(8192) - while data: - self.mesg.read(8192) - self.mesg = None - class RequestParser(Parser): def __init__(self, *args, **kwargs): super(RequestParser, self).__init__(Request, *args, **kwargs) diff --git a/gunicorn/workers/async.py b/gunicorn/workers/async.py index ff944431..4c9658fc 100644 --- a/gunicorn/workers/async.py +++ b/gunicorn/workers/async.py @@ -7,18 +7,17 @@ import errno import socket import traceback +import gunicorn.http as http +import gunicorn.http.wsgi as wsgi import gunicorn.util as util -import gunicorn.wsgi as wsgi -from gunicorn.workers.base import Worker - -from simplehttp import RequestParser +import gunicorn.workers.base as base ALREADY_HANDLED = object() -class AsyncWorker(Worker): +class AsyncWorker(base.Worker): def __init__(self, *args, **kwargs): - Worker.__init__(self, *args, **kwargs) + super(AsyncWorker, self).__init__(*args, **kwargs) self.worker_connections = self.cfg.worker_connections def timeout_ctx(self): @@ -26,7 +25,7 @@ class AsyncWorker(Worker): def handle(self, client, addr): try: - parser = RequestParser(client) + parser = http.RequestParser(client) try: while True: req = None diff --git a/gunicorn/workers/sync.py b/gunicorn/workers/sync.py index 7380ae44..2f6d1fd1 100644 --- a/gunicorn/workers/sync.py +++ b/gunicorn/workers/sync.py @@ -10,7 +10,7 @@ import select import socket import traceback -import gunicorn.http.parser as parser +import gunicorn.http as http import gunicorn.http.wsgi as wsgi import gunicorn.util as util import gunicorn.workers.base as base @@ -70,7 +70,7 @@ class SyncWorker(base.Worker): def handle(self, client, addr): try: - parser = parser.RequestParser(client) + parser = http.RequestParser(client) req = parser.next() self.handle_request(req, client, addr) except socket.error, e: