From d63890c77acef625949fc7560b65aa99b86b4329 Mon Sep 17 00:00:00 2001 From: Benoit Chesneau Date: Tue, 1 Dec 2009 15:15:27 +0100 Subject: [PATCH] full wsgi environment. --- gunicorn/httprequest.py | 13 ++++++++++--- gunicorn/httpserver.py | 7 +++---- 2 files changed, 13 insertions(+), 7 deletions(-) diff --git a/gunicorn/httprequest.py b/gunicorn/httprequest.py index b11d5fe0..8ace551d 100644 --- a/gunicorn/httprequest.py +++ b/gunicorn/httprequest.py @@ -33,9 +33,10 @@ class HTTPRequest(object): SERVER_VERSION = "gunicorn/%s" % __version__ CHUNK_SIZE = 4096 - def __init__(self, socket, address): + def __init__(self, socket, client_address, server_address): self.socket = socket - self.address = address + self.client_address = client_address + self.server_address = server_address self.version = None self.method = None self.path = None @@ -80,7 +81,12 @@ class HTTPRequest(object): "QUERY_STRING": query, "RAW_URI": self.path, "CONTENT_TYPE": self.headers.get('content-type', ''), - "CONTENT_LENGTH": length + "CONTENT_LENGTH": length, + "REMOTE_ADDR": self.client_address[0], + "REMOTE_PORT": self.client_address[1], + "SERVER_NAME": self.server_address[0], + "SERVER_PORT": self.server_address[1], + "SERVER_PROTOCOL": self.version } for key, value in self.headers.items(): @@ -88,6 +94,7 @@ class HTTPRequest(object): if key not in ('HTTP_CONTENT_TYPE', 'HTTP_CONTENT_LENGTH'): environ[key] = value + print environ return environ def read_headers(self): diff --git a/gunicorn/httpserver.py b/gunicorn/httpserver.py index 567df741..bd626a54 100644 --- a/gunicorn/httpserver.py +++ b/gunicorn/httpserver.py @@ -102,10 +102,9 @@ class HTTPServer(object): pass - def process_client(self, conn, addr): + def process_client(self, listener, conn, addr): """ do nothing just echo message""" - - req = HTTPRequest(conn, addr) + req = HTTPRequest(conn, addr, listener.getsockname()) environ = req.read() req.write(str(environ)) @@ -128,7 +127,7 @@ class HTTPServer(object): try: for sock in ready: try: - self.process_client(*sock.accept_nonblock()) + self.process_client(sock, *sock.accept_nonblock()) except errno.EAGAIN, errno.ECONNABORTED: pass