From 3cc0e5df8ae3e00dc1437b521aca32ca29f13f7b Mon Sep 17 00:00:00 2001 From: "Paul J. Davis" Date: Mon, 6 Sep 2010 15:23:30 -0700 Subject: [PATCH] Add SERVER_SOFTWARE to the os.environ Requested to allow a WSGI app to detect if its running in production or development modes. --- gunicorn/__init__.py | 1 + gunicorn/arbiter.py | 7 +++++-- gunicorn/http/wsgi.py | 7 +++---- 3 files changed, 9 insertions(+), 6 deletions(-) diff --git a/gunicorn/__init__.py b/gunicorn/__init__.py index 035497f0..6850288c 100644 --- a/gunicorn/__init__.py +++ b/gunicorn/__init__.py @@ -25,3 +25,4 @@ else: version_info = (0, 11, "1%s" % minor_tag) __version__ = ".".join(map(str, version_info)) +SERVER_SOFTWARE = "gunicorn/%s" % __version__ diff --git a/gunicorn/arbiter.py b/gunicorn/arbiter.py index 9002af8c..9ee46658 100644 --- a/gunicorn/arbiter.py +++ b/gunicorn/arbiter.py @@ -18,7 +18,8 @@ from gunicorn.errors import HaltServer from gunicorn.pidfile import Pidfile from gunicorn.sock import create_socket from gunicorn import util -from gunicorn import __version__ + +from gunicorn import __version__, SERVER_SOFTWARE class Arbiter(object): """ @@ -52,7 +53,9 @@ class Arbiter(object): def __init__(self, app): self.log = logging.getLogger(__name__) self.log.info("Starting gunicorn %s" % __version__) - + + os.environ["SERVER_SOFTWARE"] = SERVER_SOFTWARE + self.setup(app) self.pidfile = None diff --git a/gunicorn/http/wsgi.py b/gunicorn/http/wsgi.py index 6e8a4bfc..11db0199 100644 --- a/gunicorn/http/wsgi.py +++ b/gunicorn/http/wsgi.py @@ -9,10 +9,9 @@ import re import sys from urllib import unquote -from gunicorn import __version__ +from gunicorn import SERVER_SOFTWARE import gunicorn.util as util -SERVER_VERSION = "gunicorn/%s" % __version__ NORMALIZE_SPACE = re.compile(r'(?:\r\n)?[ \t]+') log = logging.getLogger(__name__) @@ -28,7 +27,7 @@ def create(req, sock, client, server, cfg): "wsgi.multiprocess": (cfg.workers > 1), "wsgi.run_once": False, "gunicorn.socket": sock, - "SERVER_SOFTWARE": SERVER_VERSION, + "SERVER_SOFTWARE": SERVER_SOFTWARE, "REQUEST_METHOD": req.method, "QUERY_STRING": req.query, "RAW_URI": req.uri, @@ -112,7 +111,7 @@ class Response(object): def __init__(self, req, sock): self.req = req self.sock = sock - self.version = SERVER_VERSION + self.version = SERVER_SOFTWARE self.status = None self.chunked = False self.should_close = req.should_close()