From 6766c14793a9705ef4aa29527f0603ce69d0a947 Mon Sep 17 00:00:00 2001 From: benoitc Date: Mon, 20 Feb 2012 07:02:55 +0100 Subject: [PATCH] pass config to the http parser. --- gunicorn/http/message.py | 8 ++++---- gunicorn/http/parser.py | 5 +++-- gunicorn/workers/async.py | 2 +- gunicorn/workers/sync.py | 2 +- 4 files changed, 9 insertions(+), 8 deletions(-) diff --git a/gunicorn/http/message.py b/gunicorn/http/message.py index 77e21b3b..3f14e882 100644 --- a/gunicorn/http/message.py +++ b/gunicorn/http/message.py @@ -16,7 +16,8 @@ from gunicorn.http.errors import InvalidHeader, InvalidHeaderName, NoMoreData, \ InvalidRequestLine, InvalidRequestMethod, InvalidHTTPVersion class Message(object): - def __init__(self, unreader): + def __init__(self, cfg, unreader): + self.cfg = cfg self.unreader = unreader self.version = None self.headers = [] @@ -96,7 +97,7 @@ class Message(object): class Request(Message): - def __init__(self, unreader): + def __init__(self, cfg, unreader): self.methre = re.compile("[A-Z0-9$-_.]{3,20}") self.versre = re.compile("HTTP/(\d+).(\d+)") @@ -106,7 +107,7 @@ class Request(Message): self.query = None self.fragment = None - super(Request, self).__init__(unreader) + super(Request, self).__init__(cfg, unreader) def get_data(self, unreader, buf, stop=False): @@ -119,7 +120,6 @@ class Request(Message): def parse(self, unreader): buf = StringIO() - self.get_data(unreader, buf, stop=True) # Request line diff --git a/gunicorn/http/parser.py b/gunicorn/http/parser.py index 92d33842..38fee43b 100644 --- a/gunicorn/http/parser.py +++ b/gunicorn/http/parser.py @@ -7,8 +7,9 @@ from gunicorn.http.message import Request from gunicorn.http.unreader import SocketUnreader, IterUnreader class Parser(object): - def __init__(self, mesg_class, source): + def __init__(self, mesg_class, cfg, source): self.mesg_class = mesg_class + self.cfg = cfg if hasattr(source, "recv"): self.unreader = SocketUnreader(source) else: @@ -30,7 +31,7 @@ class Parser(object): data = self.mesg.body.read(8192) # Parse the next request - self.mesg = self.mesg_class(self.unreader) + self.mesg = self.mesg_class(self.cfg, self.unreader) if not self.mesg: raise StopIteration() return self.mesg diff --git a/gunicorn/workers/async.py b/gunicorn/workers/async.py index 635ed831..f1f0d0ea 100644 --- a/gunicorn/workers/async.py +++ b/gunicorn/workers/async.py @@ -27,7 +27,7 @@ class AsyncWorker(base.Worker): def handle(self, client, addr): try: - parser = http.RequestParser(client) + parser = http.RequestParser(self.cfg, client) try: while True: req = None diff --git a/gunicorn/workers/sync.py b/gunicorn/workers/sync.py index 4726201a..642dcb32 100644 --- a/gunicorn/workers/sync.py +++ b/gunicorn/workers/sync.py @@ -66,7 +66,7 @@ class SyncWorker(base.Worker): def handle(self, client, addr): try: - parser = http.RequestParser(client) + parser = http.RequestParser(self.cfg, client) req = parser.next() self.handle_request(req, client, addr) except StopIteration, e: